##Install Packages if Needed
if (!require("ggplot2")) install.packages("ggplot2")
Loading required package: ggplot2
if (!require("effectsize")) install.packages("effectsize")
Loading required package: effectsize
if (!require("emmeans")) install.packages("emmeans")
Loading required package: emmeans
if (!require("dplyr")) install.packages("dplyr")
Loading required package: dplyr
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
if (!require("tidyr")) install.packages("tidyr")
Loading required package: tidyr
if (!require("Rmisc")) install.packages("Rmisc")
Loading required package: Rmisc
Loading required package: lattice
Loading required package: plyr
----------------------------------------------------------------------------------
You have loaded plyr after dplyr - this is likely to cause problems.
If you need functions from both plyr and dplyr, please load plyr first, then dplyr:
library(plyr); library(dplyr)
----------------------------------------------------------------------------------
Attaching package: ‘plyr’
The following objects are masked from ‘package:dplyr’:
arrange, count, desc, failwith, id, mutate, rename, summarise,
summarize
if (!require("ggpubr")) install.packages("ggpubr")
Loading required package: ggpubr
Attaching package: ‘ggpubr’
The following object is masked from ‘package:plyr’:
mutate
if (!require("cowplot")) install.packages("cowplot")
Loading required package: cowplot
Attaching package: ‘cowplot’
The following object is masked from ‘package:ggpubr’:
get_legend
if (!require("gridGraphics")) install.packages("gridGraphics")
Loading required package: gridGraphics
Warning: package ‘gridGraphics’ was built under R version 4.3.2Loading required package: grid
if (!require("tidyr")) install.packages("tidyr")
##Load Packages
library(ggplot2) #Required for plotting
library(effectsize) #Required for eta_squared effect sizes
library(emmeans) #Required for pairwise comparisons
library(dplyr) #Required to seperate columns in dataframe
library(tidyr) #Required for data organization
library(Rmisc) #Required for summarySE for summary statistics
library(ggpubr) #Required for adding pairwise p-values to plots with stat_pvalue_manual
library(cowplot) #Required for arranging ggplots
library(gridGraphics) #Required for adding labels to arranged plots
library(tidyr) #Required for reshaping datafrom from a wide to long format.
Note: Run “Graphing Parameters” section from 01_ExperimentalSetup.R file
Note: Full Data with Bleaching Metrics and Color Scores created in 04_Models.R file
#Load Data
FullData<-read.csv("Outputs/FullData.csv", header=TRUE)
#Set factor variables
FullData$TimeP<-factor(FullData$TimeP, levels=c("W1", "W2", "M1", "M4", "M8", "M12"), ordered=TRUE)
FullData$Site<-factor(FullData$Site, levels=c("KL", "SS"), ordered=TRUE)
FullData$Genotype<-factor(FullData$Genotype, levels=c("AC10", "AC12", "AC8"), ordered=TRUE)
FullData$Treatment<-factor(FullData$Treatment, levels=c("Control", "Heat"), ordered=TRUE)
FullData$Treat<-factor(FullData$Treat, levels=c("C", "H"), ordered=TRUE)
##Control
FullData_C<-subset(FullData, Treat=="C")
##Heated
FullData_H<-subset(FullData, Treat=="H")
Calculating retention as proportion remaining relative to corresponding control levels (0-1) for each site and genotype at each timepoint.
##Calculate averages for Control Treatment for each Site, Genotype, and Timepoint
names(FullData_C)
[1] "ID" "RandN" "TimeP" "Site"
[5] "Genotype" "Treat" "Treatment" "Set"
[9] "Score_Full" "Score_TP" "Score_Set" "Score_Seas"
[13] "AnSet" "Season" "SA_cm2" "Chl_ug.cm2"
[17] "Sym10.6_cm2"
FullData_C.a<-aggregate(FullData_C[,c(9:10, 16:17)], list(FullData_C$Site, FullData_C$Genotype, FullData_C$TimeP), mean, na.action = na.omit)
names(FullData_C.a)[1:3]<-c("Site", "Genotype", "TimeP")
names(FullData_C.a)[4:7]<-paste(names(FullData_C)[c(9:10, 16:17)], "C", sep="_")
##Merge Control Averages with Heated Samples
#Merges by Site, Genotype, and Timepoint
TolData<-merge(FullData_H, FullData_C.a, all.x=TRUE )
##Calculate Proportion Retained for each Bleaching Metric relative to Control
TolData$Score_Full.prop<-round((TolData$Score_Full/TolData$Score_Full_C), 4)
TolData$Score_TP.prop<-round((TolData$Score_TP/TolData$Score_TP_C), 4)
TolData$Chl.prop<-round((TolData$Chl_ug.cm2/TolData$Chl_ug.cm2_C), 4)
TolData$Sym.prop<-round((TolData$Sym10.6_cm2/TolData$Sym10.6_cm2_C), 4)
##Set values >1 to 1
TolData$Score_Full.prop[which(TolData$Score_Full.prop>1)]<-1.0000
TolData$Score_TP.prop[which(TolData$Score_TP.prop>1)]<-1.0000
TolData$Chl.prop[which(TolData$Chl.prop>1)]<-1.0000
TolData$Sym.prop[which(TolData$Sym.prop>1)]<-1.0000
##Create Site and Genotype Variable
TolData$Site.Geno<-paste(TolData$Site, TolData$Genotype, sep="_")
TolData_W1<-subset(TolData, TimeP=="W1")
TolData_W2<-subset(TolData, TimeP=="W2")
TolData_M1<-subset(TolData, TimeP=="M1")
TolData_M4<-subset(TolData, TimeP=="M4")
TolData_M8<-subset(TolData, TimeP=="M8")
TolData_M12<-subset(TolData, TimeP=="M12")
##Check normality
hist(TolData$Chl.prop)
shapiro.test(TolData$Chl.prop)
Shapiro-Wilk normality test
data: TolData$Chl.prop
W = 0.87577, p-value = 2.433e-09
#Not Normal
##Try log transformation
hist(log(TolData$Chl.prop))
shapiro.test(log(TolData$Chl.prop))
Shapiro-Wilk normality test
data: log(TolData$Chl.prop)
W = 0.97275, p-value = 0.007572
#Not normal but improved
##Try square root transformation
hist(sqrt(TolData$Chl.prop))
shapiro.test(log(TolData$Chl.prop))
Shapiro-Wilk normality test
data: log(TolData$Chl.prop)
W = 0.97275, p-value = 0.007572
#Not normal but much improved
##Model as a function of Site and Genotype and Timepoint
##Model with sqrt transformation
Tol_Chl_lm<-lm(sqrt(Chl.prop)~Site+Genotype+TimeP+ Site:Genotype + Site:TimeP + Genotype:TimeP, data=TolData)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_lm)); qqline(resid(Tol_Chl_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_lm), resid(Tol_Chl_lm))
#Model Results
summary(Tol_Chl_lm)
Call:
lm(formula = sqrt(Chl.prop) ~ Site + Genotype + TimeP + Site:Genotype +
Site:TimeP + Genotype:TimeP, data = TolData)
Residuals:
Min 1Q Median 3Q Max
-0.161251 -0.046726 0.002497 0.047694 0.155492
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.452966 0.006329 71.574 < 2e-16 ***
Site.L -0.015067 0.008943 -1.685 0.094840 .
Genotype.L -0.062429 0.010774 -5.794 6.51e-08 ***
Genotype.Q -0.028845 0.011149 -2.587 0.010963 *
TimeP.L 0.074391 0.015473 4.808 4.83e-06 ***
TimeP.Q -0.163442 0.015445 -10.582 < 2e-16 ***
TimeP.C -0.246251 0.015541 -15.845 < 2e-16 ***
TimeP^4 -0.194710 0.015559 -12.515 < 2e-16 ***
TimeP^5 -0.031239 0.015492 -2.017 0.046157 *
Site.L:Genotype.L 0.042483 0.015237 2.788 0.006237 **
Site.L:Genotype.Q 0.076176 0.015753 4.836 4.30e-06 ***
Site.L:TimeP.L -0.009791 0.021881 -0.447 0.655430
Site.L:TimeP.Q -0.044698 0.021792 -2.051 0.042608 *
Site.L:TimeP.C 0.038173 0.021968 1.738 0.085041 .
Site.L:TimeP^4 -0.052140 0.021983 -2.372 0.019422 *
Site.L:TimeP^5 -0.038620 0.021831 -1.769 0.079630 .
Genotype.L:TimeP.L 0.181790 0.026311 6.909 3.22e-10 ***
Genotype.Q:TimeP.L 0.085212 0.027251 3.127 0.002256 **
Genotype.L:TimeP.Q 0.046286 0.026082 1.775 0.078706 .
Genotype.Q:TimeP.Q 0.022110 0.027395 0.807 0.421335
Genotype.L:TimeP.C -0.118908 0.026590 -4.472 1.88e-05 ***
Genotype.Q:TimeP.C 0.063014 0.027179 2.318 0.022256 *
Genotype.L:TimeP^4 -0.106570 0.026696 -3.992 0.000118 ***
Genotype.Q:TimeP^4 0.004505 0.027155 0.166 0.868544
Genotype.L:TimeP^5 0.039262 0.026254 1.496 0.137620
Genotype.Q:TimeP^5 -0.138355 0.027376 -5.054 1.72e-06 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.0737 on 111 degrees of freedom
(3 observations deleted due to missingness)
Multiple R-squared: 0.8756, Adjusted R-squared: 0.8476
F-statistic: 31.26 on 25 and 111 DF, p-value: < 2.2e-16
anova(Tol_Chl_lm)
Analysis of Variance Table
Response: sqrt(Chl.prop)
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.01081 0.01081 1.9894 0.161201
Genotype 2 0.24811 0.12405 22.8362 4.936e-09 ***
TimeP 5 3.00659 0.60132 110.6917 < 2.2e-16 ***
Site:Genotype 2 0.17669 0.08834 16.2624 6.397e-07 ***
Site:TimeP 5 0.09374 0.01875 3.4513 0.006159 **
Genotype:TimeP 10 0.70955 0.07096 13.0616 7.640e-15 ***
Residuals 111 0.60299 0.00543
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Chl_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
----------------------------------------
Site | 2.23e-03 | [0.00, 1.00]
Genotype | 0.05 | [0.00, 1.00]
TimeP | 0.62 | [0.52, 1.00]
Site:Genotype | 0.04 | [0.00, 1.00]
Site:TimeP | 0.02 | [0.00, 1.00]
Genotype:TimeP | 0.15 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_lm.res<-data.frame(anova(Tol_Chl_lm))
Tol_Chl_lm.res$Predictor<-rownames(Tol_Chl_lm.res)
Tol_Chl_lm.res$EtaSq<-c(eta_squared(Tol_Chl_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_lm.res))
Tol_Chl_lm.res<-Tol_Chl_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Strong influence of Timepoint, including interactions with main variables of interest, Site and Genotype. Will analyze each Timepoint individually.
##Check normality
hist(TolData_W1$Chl.prop)
shapiro.test(TolData_W1$Chl.prop)
Shapiro-Wilk normality test
data: TolData_W1$Chl.prop
W = 0.90425, p-value = 0.03095
#Not Normal
##Try log+1 transformation
hist(log(TolData_W1$Chl.prop+1))
shapiro.test(log(TolData_W1$Chl.prop+1))
Shapiro-Wilk normality test
data: log(TolData_W1$Chl.prop + 1)
W = 0.92076, p-value = 0.06917
#Normal
##Model as a function of Site and Genotype
##Model with log+1 transformation
Tol_Chl_W1_lm<-lm(log(Chl.prop+1)~Site+Genotype+Site:Genotype, data=TolData_W1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_W1_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_W1_lm)); qqline(resid(Tol_Chl_W1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_W1_lm), resid(Tol_Chl_W1_lm))
#Model Results
summary(Tol_Chl_W1_lm)
Call:
lm(formula = log(Chl.prop + 1) ~ Site + Genotype + Site:Genotype,
data = TolData_W1)
Residuals:
Min 1Q Median 3Q Max
-0.082776 -0.019331 -0.009257 0.018133 0.101612
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.142259 0.009259 15.365 2.11e-11 ***
Site.L -0.049071 0.013094 -3.748 0.001603 **
Genotype.L -0.076006 0.015609 -4.869 0.000144 ***
Genotype.Q -0.050863 0.016453 -3.091 0.006626 **
Site.L:Genotype.L 0.074725 0.022074 3.385 0.003519 **
Site.L:Genotype.Q 0.079154 0.023269 3.402 0.003395 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.04415 on 17 degrees of freedom
Multiple R-squared: 0.8104, Adjusted R-squared: 0.7546
F-statistic: 14.53 on 5 and 17 DF, p-value: 1.259e-05
anova(Tol_Chl_W1_lm)
Analysis of Variance Table
Response: log(Chl.prop + 1)
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.027338 0.027338 14.025 0.0016121 **
Genotype 2 0.069398 0.034699 17.802 6.762e-05 ***
Site:Genotype 2 0.044890 0.022445 11.515 0.0006894 ***
Residuals 17 0.033135 0.001949
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Chl_W1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.16 | [0.00, 1.00]
Genotype | 0.40 | [0.07, 1.00]
Site:Genotype | 0.26 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_W1_lm.res<-data.frame(anova(Tol_Chl_W1_lm))
Tol_Chl_W1_lm.res$Predictor<-rownames(Tol_Chl_W1_lm.res)
Tol_Chl_W1_lm.res$EtaSq<-c(eta_squared(Tol_Chl_W1_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_W1_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_W1_lm.res))
Tol_Chl_W1_lm.res$TimeP<-rep("W1", nrow(Tol_Chl_W1_lm.res))
Tol_Chl_W1_lm.res<-Tol_Chl_W1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype and Site*Genotype.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Chl_W1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.2244 0.0221 17 0.17788 0.2710
AC12 0.2642 0.0221 17 0.21761 0.3108
AC8 0.0422 0.0221 17 -0.00434 0.0888
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.1260 0.0221 17 0.07945 0.1726
AC12 0.1034 0.0255 17 0.04961 0.1572
AC8 0.0933 0.0221 17 0.04669 0.1398
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.0397 0.0312 17 -1.273 0.4289
AC10 - AC8 0.1822 0.0312 17 5.837 0.0001
AC12 - AC8 0.2219 0.0312 17 7.110 <.0001
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0226 0.0337 17 0.671 0.7830
AC10 - AC8 0.0328 0.0312 17 1.049 0.5570
AC12 - AC8 0.0101 0.0337 17 0.300 0.9516
Note: contrasts are still on the log(mu + 1) scale
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Chl_W1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.2244 0.0221 17 0.17788 0.2710
SS 0.1260 0.0221 17 0.07945 0.1726
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.2642 0.0221 17 0.21761 0.3108
SS 0.1034 0.0255 17 0.04961 0.1572
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.0422 0.0221 17 -0.00434 0.0888
SS 0.0933 0.0221 17 0.04669 0.1398
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.0984 0.0312 17 3.153 0.0058
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.1608 0.0337 17 4.769 0.0002
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0510 0.0312 17 -1.635 0.1205
Note: contrasts are still on the log(mu + 1) scale
##Save p-values
#Genotypes within Sites
Tol_Chl_W1_lm.geno<-data.frame(emmeans(Tol_Chl_W1_lm, pairwise~Genotype | Site)$contrasts)
Tol_Chl_W1_lm.geno<-Tol_Chl_W1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_W1_lm.geno$group1<-paste(Tol_Chl_W1_lm.geno$Site, Tol_Chl_W1_lm.geno$group1, sep="_")
Tol_Chl_W1_lm.geno$group2<-paste(Tol_Chl_W1_lm.geno$Site, Tol_Chl_W1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Chl_W1_lm.site<-data.frame(emmeans(Tol_Chl_W1_lm, pairwise~Site | Genotype)$contrasts)
Tol_Chl_W1_lm.site<-Tol_Chl_W1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_W1_lm.site$group1<-paste(Tol_Chl_W1_lm.site$group1, Tol_Chl_W1_lm.site$Genotype, sep="_")
Tol_Chl_W1_lm.site$group2<-paste(Tol_Chl_W1_lm.site$group2, Tol_Chl_W1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Chl_W1_lm.p<-rbind(Tol_Chl_W1_lm.geno[,c(1:2,4:8)], Tol_Chl_W1_lm.site[,c(1:2,4:8)])
Tol_Chl_W1_lm.p<-Tol_Chl_W1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Chl_W1_lm.p$Sig<-ifelse(Tol_Chl_W1_lm.p$p<0.001, "***", ifelse(Tol_Chl_W1_lm.p$p<0.01, "**", ifelse(Tol_Chl_W1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Chl_W1_lm.p$Response<-rep("Chlorophyll", nrow(Tol_Chl_W1_lm.p))
Tol_Chl_W1_lm.p$TimeP<-rep("W1", nrow(Tol_Chl_W1_lm.p))
##Summary statistics by Site and Genotype
Tol_Chl_W1_SG<-summarySE(TolData_W1, measurevar="Chl.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Chl_W1_SG.plot<-ggplot(Tol_Chl_W1_SG, aes(x=Site.Geno, y=Chl.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Chlorophyll Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Chl_W1_lm.p, y.position=0.4, step.increase=0.25, label="Sig", hide.ns=TRUE); Tol_Chl_W1_SG.plot
##Check normality
hist(TolData_W2$Chl.prop)
shapiro.test(TolData_W2$Chl.prop)
Shapiro-Wilk normality test
data: TolData_W2$Chl.prop
W = 0.98407, p-value = 0.9671
#Normal
##Model as a function of Site and Genotype
Tol_Chl_W2_lm<-lm(Chl.prop~Site+Genotype+Site:Genotype, data=TolData_W2)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_W2_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_W2_lm)); qqline(resid(Tol_Chl_W2_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_W2_lm), resid(Tol_Chl_W2_lm))
#Model Results
summary(Tol_Chl_W2_lm)
Call:
lm(formula = Chl.prop ~ Site + Genotype + Site:Genotype, data = TolData_W2)
Residuals:
Min 1Q Median 3Q Max
-0.089900 -0.031587 -0.008183 0.038881 0.103550
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.1842264 0.0119450 15.423 5.03e-11 ***
Site.L 0.0188110 0.0168928 1.114 0.281921
Genotype.L -0.0947759 0.0204291 -4.639 0.000273 ***
Genotype.Q -0.0585870 0.0209464 -2.797 0.012921 *
Site.L:Genotype.L -0.0002833 0.0288911 -0.010 0.992297
Site.L:Genotype.Q 0.0366569 0.0296227 1.237 0.233769
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.05552 on 16 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.6758, Adjusted R-squared: 0.5745
F-statistic: 6.671 on 5 and 16 DF, p-value: 0.001551
anova(Tol_Chl_W2_lm)
Analysis of Variance Table
Response: Chl.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.005580 0.005580 1.8106 0.197195
Genotype 2 0.092482 0.046241 15.0038 0.000214 ***
Site:Genotype 2 0.004732 0.002366 0.7677 0.480448
Residuals 16 0.049311 0.003082
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Chl_W2_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.04 | [0.00, 1.00]
Genotype | 0.61 | [0.29, 1.00]
Site:Genotype | 0.03 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_W2_lm.res<-data.frame(anova(Tol_Chl_W2_lm))
Tol_Chl_W2_lm.res$Predictor<-rownames(Tol_Chl_W2_lm.res)
Tol_Chl_W2_lm.res$EtaSq<-c(eta_squared(Tol_Chl_W2_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_W2_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_W2_lm.res))
Tol_Chl_W2_lm.res$TimeP<-rep("W2", nrow(Tol_Chl_W2_lm.res))
Tol_Chl_W2_lm.res<-Tol_Chl_W2_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Chl_W2_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.2033 0.0278 16 0.1445 0.262
AC12 0.2399 0.0278 16 0.1811 0.299
AC8 0.0696 0.0278 16 0.0107 0.128
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.2514 0.0278 16 0.1925 0.310
AC12 0.2242 0.0321 16 0.1563 0.292
AC8 0.1170 0.0321 16 0.0491 0.185
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.0366 0.0393 16 -0.933 0.6280
AC10 - AC8 0.1338 0.0393 16 3.407 0.0095
AC12 - AC8 0.1704 0.0393 16 4.340 0.0014
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0272 0.0424 16 0.640 0.8003
AC10 - AC8 0.1343 0.0424 16 3.168 0.0156
AC12 - AC8 0.1072 0.0453 16 2.364 0.0753
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Chl_W2_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.2033 0.0278 16 0.1445 0.262
SS 0.2514 0.0278 16 0.1925 0.310
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.2399 0.0278 16 0.1811 0.299
SS 0.2242 0.0321 16 0.1563 0.292
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.0696 0.0278 16 0.0107 0.128
SS 0.1170 0.0321 16 0.0491 0.185
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0481 0.0393 16 -1.224 0.2387
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.0157 0.0424 16 0.371 0.7156
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0475 0.0424 16 -1.120 0.2793
##Save p-values
#Genotypes within Sites
Tol_Chl_W2_lm.geno<-data.frame(emmeans(Tol_Chl_W2_lm, pairwise~Genotype | Site)$contrasts)
Tol_Chl_W2_lm.geno<-Tol_Chl_W2_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_W2_lm.geno$group1<-paste(Tol_Chl_W2_lm.geno$Site, Tol_Chl_W2_lm.geno$group1, sep="_")
Tol_Chl_W2_lm.geno$group2<-paste(Tol_Chl_W2_lm.geno$Site, Tol_Chl_W2_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Chl_W2_lm.site<-data.frame(emmeans(Tol_Chl_W2_lm, pairwise~Site | Genotype)$contrasts)
Tol_Chl_W2_lm.site<-Tol_Chl_W2_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_W2_lm.site$group1<-paste(Tol_Chl_W2_lm.site$group1, Tol_Chl_W2_lm.site$Genotype, sep="_")
Tol_Chl_W2_lm.site$group2<-paste(Tol_Chl_W2_lm.site$group2, Tol_Chl_W2_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Chl_W2_lm.p<-rbind(Tol_Chl_W2_lm.geno[,c(1:2,4:8)], Tol_Chl_W2_lm.site[,c(1:2,4:8)])
Tol_Chl_W2_lm.p<-Tol_Chl_W2_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Chl_W2_lm.p$Sig<-ifelse(Tol_Chl_W2_lm.p$p<0.001, "***", ifelse(Tol_Chl_W2_lm.p$p<0.01, "**", ifelse(Tol_Chl_W2_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Chl_W2_lm.p$Response<-rep("Chlorophyll", nrow(Tol_Chl_W2_lm.p))
Tol_Chl_W2_lm.p$TimeP<-rep("W2", nrow(Tol_Chl_W2_lm.p))
##Summary statistics by Site and Genotype
Tol_Chl_W2_SG<-summarySE(TolData_W2, measurevar="Chl.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Chl_W2_SG.plot<-ggplot(Tol_Chl_W2_SG, aes(x=Site.Geno, y=Chl.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Chlorophyll Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Chl_W2_lm.p, y.position=0.4, step.increase=0.25, label="Sig", hide.ns=TRUE); Tol_Chl_W2_SG.plot
##Check normality
hist(TolData_M1$Chl.prop)
shapiro.test(TolData_M1$Chl.prop)
Shapiro-Wilk normality test
data: TolData_M1$Chl.prop
W = 0.9306, p-value = 0.1263
#Normal
##Model as a function of Site and Genotype
Tol_Chl_M1_lm<-lm(Chl.prop~Site+Genotype+Site:Genotype, data=TolData_M1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_M1_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_M1_lm)); qqline(resid(Tol_Chl_M1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_M1_lm), resid(Tol_Chl_M1_lm))
#Model Results
summary(Tol_Chl_M1_lm)
Call:
lm(formula = Chl.prop ~ Site + Genotype + Site:Genotype, data = TolData_M1)
Residuals:
Min 1Q Median 3Q Max
-0.107050 -0.034575 0.003479 0.025531 0.088050
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.17217 0.01178 14.619 1.12e-10 ***
Site.L 0.01036 0.01666 0.622 0.5428
Genotype.L -0.16337 0.01935 -8.442 2.74e-07 ***
Genotype.Q 0.06169 0.02139 2.883 0.0108 *
Site.L:Genotype.L 0.03819 0.02737 1.395 0.1820
Site.L:Genotype.Q 0.05454 0.03026 1.803 0.0903 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.05474 on 16 degrees of freedom
Multiple R-squared: 0.8424, Adjusted R-squared: 0.7932
F-statistic: 17.11 on 5 and 16 DF, p-value: 6.411e-06
anova(Tol_Chl_M1_lm)
Analysis of Variance Table
Response: Chl.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.002283 0.002283 0.7619 0.3956
Genotype 2 0.238424 0.119212 39.7888 6.168e-07 ***
Site:Genotype 2 0.015569 0.007785 2.5982 0.1054
Residuals 16 0.047938 0.002996
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Chl_M1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 7.50e-03 | [0.00, 1.00]
Genotype | 0.78 | [0.58, 1.00]
Site:Genotype | 0.05 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_M1_lm.res<-data.frame(anova(Tol_Chl_M1_lm))
Tol_Chl_M1_lm.res$Predictor<-rownames(Tol_Chl_M1_lm.res)
Tol_Chl_M1_lm.res$EtaSq<-c(eta_squared(Tol_Chl_M1_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_M1_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_M1_lm.res))
Tol_Chl_M1_lm.res$TimeP<-rep("M1", nrow(Tol_Chl_M1_lm.res))
Tol_Chl_M1_lm.res<-Tol_Chl_M1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Chl_M1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.3089 0.0274 16 0.2509 0.3669
AC12 0.1460 0.0316 16 0.0790 0.2130
AC8 0.0397 0.0274 16 -0.0183 0.0977
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.3169 0.0274 16 0.2588 0.3749
AC12 0.0976 0.0316 16 0.0306 0.1646
AC8 0.1240 0.0274 16 0.0660 0.1820
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1629 0.0418 16 3.897 0.0035
AC10 - AC8 0.2692 0.0387 16 6.956 <.0001
AC12 - AC8 0.1063 0.0418 16 2.543 0.0538
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.2192 0.0418 16 5.244 0.0002
AC10 - AC8 0.1928 0.0387 16 4.983 0.0004
AC12 - AC8 -0.0264 0.0418 16 -0.631 0.8056
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Chl_M1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.3089 0.0274 16 0.2509 0.3669
SS 0.3169 0.0274 16 0.2588 0.3749
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.1460 0.0316 16 0.0790 0.2130
SS 0.0976 0.0316 16 0.0306 0.1646
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.0397 0.0274 16 -0.0183 0.0977
SS 0.1240 0.0274 16 0.0660 0.1820
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.00795 0.0387 16 -0.205 0.8398
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.04833 0.0447 16 1.081 0.2955
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.08432 0.0387 16 -2.179 0.0447
##Save p-values
#Genotypes within Sites
Tol_Chl_M1_lm.geno<-data.frame(emmeans(Tol_Chl_M1_lm, pairwise~Genotype | Site)$contrasts)
Tol_Chl_M1_lm.geno<-Tol_Chl_M1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M1_lm.geno$group1<-paste(Tol_Chl_M1_lm.geno$Site, Tol_Chl_M1_lm.geno$group1, sep="_")
Tol_Chl_M1_lm.geno$group2<-paste(Tol_Chl_M1_lm.geno$Site, Tol_Chl_M1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Chl_M1_lm.site<-data.frame(emmeans(Tol_Chl_M1_lm, pairwise~Site | Genotype)$contrasts)
Tol_Chl_M1_lm.site<-Tol_Chl_M1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M1_lm.site$group1<-paste(Tol_Chl_M1_lm.site$group1, Tol_Chl_M1_lm.site$Genotype, sep="_")
Tol_Chl_M1_lm.site$group2<-paste(Tol_Chl_M1_lm.site$group2, Tol_Chl_M1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Chl_M1_lm.p<-rbind(Tol_Chl_M1_lm.geno[,c(1:2,4:8)], Tol_Chl_M1_lm.site[,c(1:2,4:8)])
Tol_Chl_M1_lm.p<-Tol_Chl_M1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Chl_M1_lm.p$Sig<-ifelse(Tol_Chl_M1_lm.p$p<0.001, "***", ifelse(Tol_Chl_M1_lm.p$p<0.01, "**", ifelse(Tol_Chl_M1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Chl_M1_lm.p$Response<-rep("Chlorophyll", nrow(Tol_Chl_M1_lm.p))
Tol_Chl_M1_lm.p$TimeP<-rep("M1", nrow(Tol_Chl_M1_lm.p))
##Summary statistics by Site and Genotype
Tol_Chl_M1_SG<-summarySE(TolData_M1, measurevar="Chl.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Chl_M1_SG.plot<-ggplot(Tol_Chl_M1_SG, aes(x=Site.Geno, y=Chl.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Chlorophyll Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Chl_M1_lm.p, y.position=0.4, step.increase=0.25, label="Sig", hide.ns=TRUE); Tol_Chl_M1_SG.plot
##Check normality
hist(TolData_M4$Chl.prop)
shapiro.test(TolData_M4$Chl.prop)
Shapiro-Wilk normality test
data: TolData_M4$Chl.prop
W = 0.91299, p-value = 0.04096
#Not Normal
##Try log+1 transformation
hist(log(TolData_M4$Chl.prop+1))
shapiro.test(log(TolData_M4$Chl.prop+1))
Shapiro-Wilk normality test
data: log(TolData_M4$Chl.prop + 1)
W = 0.93102, p-value = 0.1028
#Normal
##Model as a function of Site and Genotype
##Model with log transformation
Tol_Chl_M4_lm<-lm(log(Chl.prop+1)~Site+Genotype+Site:Genotype, data=TolData_M4)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_M4_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_M4_lm)); qqline(resid(Tol_Chl_M4_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_M4_lm), resid(Tol_Chl_M4_lm))
#Model Results
summary(Tol_Chl_M4_lm)
Call:
lm(formula = log(Chl.prop + 1) ~ Site + Genotype + Site:Genotype,
data = TolData_M4)
Residuals:
Min 1Q Median 3Q Max
-0.062753 -0.025900 -0.004896 0.017009 0.065759
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.23863 0.00807 29.568 < 2e-16 ***
Site.L -0.04272 0.01141 -3.743 0.00149 **
Genotype.L -0.03027 0.01398 -2.166 0.04400 *
Genotype.Q -0.11052 0.01398 -7.907 2.9e-07 ***
Site.L:Genotype.L -0.03189 0.01977 -1.613 0.12415
Site.L:Genotype.Q 0.05753 0.01977 2.910 0.00934 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.03954 on 18 degrees of freedom
Multiple R-squared: 0.8368, Adjusted R-squared: 0.7915
F-statistic: 18.46 on 5 and 18 DF, p-value: 1.598e-06
anova(Tol_Chl_M4_lm)
Analysis of Variance Table
Response: log(Chl.prop + 1)
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.021901 0.021901 14.0102 0.001489 **
Genotype 2 0.105056 0.052528 33.6031 8.379e-07 ***
Site:Genotype 2 0.017304 0.008652 5.5349 0.013381 *
Residuals 18 0.028137 0.001563
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Chl_M4_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.13 | [0.00, 1.00]
Genotype | 0.61 | [0.32, 1.00]
Site:Genotype | 0.10 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_M4_lm.res<-data.frame(anova(Tol_Chl_M4_lm))
Tol_Chl_M4_lm.res$Predictor<-rownames(Tol_Chl_M4_lm.res)
Tol_Chl_M4_lm.res$EtaSq<-c(eta_squared(Tol_Chl_M4_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_M4_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_M4_lm.res))
Tol_Chl_M4_lm.res$TimeP<-rep("M4", nrow(Tol_Chl_M4_lm.res))
Tol_Chl_M4_lm.res<-Tol_Chl_M4_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype and Site*Genotype.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Chl_M4_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.213 0.0198 18 0.171 0.254
AC12 0.392 0.0198 18 0.351 0.434
AC8 0.202 0.0198 18 0.160 0.243
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.217 0.0198 18 0.176 0.259
AC12 0.265 0.0198 18 0.224 0.307
AC8 0.143 0.0198 18 0.101 0.184
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.1797 0.028 18 -6.428 <.0001
AC10 - AC8 0.0109 0.028 18 0.391 0.9196
AC12 - AC8 0.1906 0.028 18 6.819 <.0001
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.0482 0.028 18 -1.724 0.2237
AC10 - AC8 0.0747 0.028 18 2.672 0.0393
AC12 - AC8 0.1229 0.028 18 4.396 0.0010
Note: contrasts are still on the log(mu + 1) scale
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Chl_M4_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.213 0.0198 18 0.171 0.254
SS 0.217 0.0198 18 0.176 0.259
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.392 0.0198 18 0.351 0.434
SS 0.265 0.0198 18 0.224 0.307
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.202 0.0198 18 0.160 0.243
SS 0.143 0.0198 18 0.101 0.184
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.00468 0.028 18 -0.167 0.8688
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.12684 0.028 18 4.537 0.0003
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.05909 0.028 18 2.114 0.0488
Note: contrasts are still on the log(mu + 1) scale
##Save p-values
#Genotypes within Sites
Tol_Chl_M4_lm.geno<-data.frame(emmeans(Tol_Chl_M4_lm, pairwise~Genotype | Site)$contrasts)
Tol_Chl_M4_lm.geno<-Tol_Chl_M4_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M4_lm.geno$group1<-paste(Tol_Chl_M4_lm.geno$Site, Tol_Chl_M4_lm.geno$group1, sep="_")
Tol_Chl_M4_lm.geno$group2<-paste(Tol_Chl_M4_lm.geno$Site, Tol_Chl_M4_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Chl_M4_lm.site<-data.frame(emmeans(Tol_Chl_M4_lm, pairwise~Site | Genotype)$contrasts)
Tol_Chl_M4_lm.site<-Tol_Chl_M4_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M4_lm.site$group1<-paste(Tol_Chl_M4_lm.site$group1, Tol_Chl_M4_lm.site$Genotype, sep="_")
Tol_Chl_M4_lm.site$group2<-paste(Tol_Chl_M4_lm.site$group2, Tol_Chl_M4_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Chl_M4_lm.p<-rbind(Tol_Chl_M4_lm.geno[,c(1:2,4:8)], Tol_Chl_M4_lm.site[,c(1:2,4:8)])
Tol_Chl_M4_lm.p<-Tol_Chl_M4_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Chl_M4_lm.p$Sig<-ifelse(Tol_Chl_M4_lm.p$p<0.001, "***", ifelse(Tol_Chl_M4_lm.p$p<0.01, "**", ifelse(Tol_Chl_M4_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Chl_M4_lm.p$Response<-rep("Chlorophyll", nrow(Tol_Chl_M4_lm.p))
Tol_Chl_M4_lm.p$TimeP<-rep("M4", nrow(Tol_Chl_M4_lm.p))
##Summary statistics by Site and Genotype
Tol_Chl_M4_SG<-summarySE(TolData_M4, measurevar="Chl.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Chl_M4_SG.plot<-ggplot(Tol_Chl_M4_SG, aes(x=Site.Geno, y=Chl.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Chlorophyll Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Chl_M4_lm.p, y.position=0.55, step.increase=0.20, label="Sig", hide.ns=TRUE); Tol_Chl_M4_SG.plot
##Check normality
hist(TolData_M8$Chl.prop)
shapiro.test(TolData_M8$Chl.prop)
Shapiro-Wilk normality test
data: TolData_M8$Chl.prop
W = 0.91958, p-value = 0.06527
#Normal
##Model as a function of Site and Genotype
Tol_Chl_M8_lm<-lm(Chl.prop~Site+Genotype+Site:Genotype, data=TolData_M8)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_M8_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_M8_lm)); qqline(resid(Tol_Chl_M8_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_M8_lm), resid(Tol_Chl_M8_lm))
#Model Results
summary(Tol_Chl_M8_lm)
Call:
lm(formula = Chl.prop ~ Site + Genotype + Site:Genotype, data = TolData_M8)
Residuals:
Min 1Q Median 3Q Max
-0.289450 -0.084387 -0.004075 0.108575 0.201950
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.56837 0.03013 18.864 7.76e-13 ***
Site.L 0.01907 0.04261 0.448 0.66009
Genotype.L 0.16787 0.05287 3.175 0.00553 **
Genotype.Q 0.01544 0.05149 0.300 0.76793
Site.L:Genotype.L 0.10868 0.07477 1.454 0.16428
Site.L:Genotype.Q 0.12765 0.07282 1.753 0.09764 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1437 on 17 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.4847, Adjusted R-squared: 0.3331
F-statistic: 3.198 on 5 and 17 DF, p-value: 0.03243
anova(Tol_Chl_M8_lm)
Analysis of Variance Table
Response: Chl.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.00863 0.008631 0.4182 0.52649
Genotype 2 0.20931 0.104656 5.0704 0.01875 *
Site:Genotype 2 0.11206 0.056028 2.7145 0.09483 .
Residuals 17 0.35089 0.020640
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Chl_M8_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.01 | [0.00, 1.00]
Genotype | 0.31 | [0.01, 1.00]
Site:Genotype | 0.16 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_M8_lm.res<-data.frame(anova(Tol_Chl_M8_lm))
Tol_Chl_M8_lm.res$Predictor<-rownames(Tol_Chl_M8_lm.res)
Tol_Chl_M8_lm.res$EtaSq<-c(eta_squared(Tol_Chl_M8_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_M8_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_M8_lm.res))
Tol_Chl_M8_lm.res$TimeP<-rep("M8", nrow(Tol_Chl_M8_lm.res))
Tol_Chl_M8_lm.res<-Tol_Chl_M8_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Marginal effect (p<0.1) of Site * Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Chl_M8_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.460 0.0718 17 0.308 0.612
AC12 0.616 0.0718 17 0.464 0.768
AC8 0.589 0.0718 17 0.437 0.740
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.452 0.0829 17 0.277 0.627
AC12 0.496 0.0718 17 0.344 0.647
AC8 0.798 0.0718 17 0.646 0.950
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.1560 0.102 17 -1.536 0.2998
AC10 - AC8 -0.1287 0.102 17 -1.267 0.4320
AC12 - AC8 0.0273 0.102 17 0.268 0.9611
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.0436 0.110 17 -0.397 0.9171
AC10 - AC8 -0.3461 0.110 17 -3.154 0.0152
AC12 - AC8 -0.3025 0.102 17 -2.978 0.0218
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Chl_M8_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.460 0.0718 17 0.308 0.612
SS 0.452 0.0829 17 0.277 0.627
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.616 0.0718 17 0.464 0.768
SS 0.496 0.0718 17 0.344 0.647
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.589 0.0718 17 0.437 0.740
SS 0.798 0.0718 17 0.646 0.950
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.00801 0.110 17 0.073 0.9427
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.12043 0.102 17 1.185 0.2522
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.20935 0.102 17 -2.061 0.0550
##Save p-values
#Genotypes within Sites
Tol_Chl_M8_lm.geno<-data.frame(emmeans(Tol_Chl_M8_lm, pairwise~Genotype | Site)$contrasts)
Tol_Chl_M8_lm.geno<-Tol_Chl_M8_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M8_lm.geno$group1<-paste(Tol_Chl_M8_lm.geno$Site, Tol_Chl_M8_lm.geno$group1, sep="_")
Tol_Chl_M8_lm.geno$group2<-paste(Tol_Chl_M8_lm.geno$Site, Tol_Chl_M8_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Chl_M8_lm.site<-data.frame(emmeans(Tol_Chl_M8_lm, pairwise~Site | Genotype)$contrasts)
Tol_Chl_M8_lm.site<-Tol_Chl_M8_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M8_lm.site$group1<-paste(Tol_Chl_M8_lm.site$group1, Tol_Chl_M8_lm.site$Genotype, sep="_")
Tol_Chl_M8_lm.site$group2<-paste(Tol_Chl_M8_lm.site$group2, Tol_Chl_M8_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Chl_M8_lm.p<-rbind(Tol_Chl_M8_lm.geno[,c(1:2,4:8)], Tol_Chl_M8_lm.site[,c(1:2,4:8)])
Tol_Chl_M8_lm.p<-Tol_Chl_M8_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Chl_M8_lm.p$Sig<-ifelse(Tol_Chl_M8_lm.p$p<0.001, "***", ifelse(Tol_Chl_M8_lm.p$p<0.01, "**", ifelse(Tol_Chl_M8_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Chl_M8_lm.p$Response<-rep("Chlorophyll", nrow(Tol_Chl_M8_lm.p))
Tol_Chl_M8_lm.p$TimeP<-rep("M8", nrow(Tol_Chl_M8_lm.p))
##Summary statistics by Site and Genotype
Tol_Chl_M8_SG<-summarySE(TolData_M8, measurevar="Chl.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Chl_M8_SG.plot<-ggplot(Tol_Chl_M8_SG, aes(x=Site.Geno, y=Chl.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Chlorophyll Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Chl_M8_lm.p, y.position=0.65, step.increase=0.6, label="Sig", hide.ns=TRUE); Tol_Chl_M8_SG.plot
##Check normality
hist(TolData_M12$Chl.prop)
shapiro.test(TolData_M12$Chl.prop)
Shapiro-Wilk normality test
data: TolData_M12$Chl.prop
W = 0.91232, p-value = 0.04572
#Not Normal
##Try log+1 transformation
hist(log(TolData_M12$Chl.prop+1))
shapiro.test(log(TolData_M12$Chl.prop+1))
Shapiro-Wilk normality test
data: log(TolData_M12$Chl.prop + 1)
W = 0.92396, p-value = 0.08104
#Normal
##Model as a function of Site and Genotype
##Model with log transformation
Tol_Chl_M12_lm<-lm(log(Chl.prop+1)~Site+Genotype+Site:Genotype, data=TolData_M12)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Chl_M12_lm)))
#Q-Q plot
qqnorm(resid(Tol_Chl_M12_lm)); qqline(resid(Tol_Chl_M12_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Chl_M12_lm), resid(Tol_Chl_M12_lm))
#Model Results
summary(Tol_Chl_M12_lm)
Call:
lm(formula = log(Chl.prop + 1) ~ Site + Genotype + Site:Genotype,
data = TolData_M12)
Residuals:
Min 1Q Median 3Q Max
-0.058954 -0.020387 -0.005506 0.017762 0.103832
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.079668 0.009314 8.553 1.45e-07 ***
Site.L -0.020944 0.013173 -1.590 0.130
Genotype.L 0.005873 0.015703 0.374 0.713
Genotype.Q 0.020903 0.016552 1.263 0.224
Site.L:Genotype.L 0.013279 0.022207 0.598 0.558
Site.L:Genotype.Q 0.028084 0.023408 1.200 0.247
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.04441 on 17 degrees of freedom
(1 observation deleted due to missingness)
Multiple R-squared: 0.2381, Adjusted R-squared: 0.01406
F-statistic: 1.063 on 5 and 17 DF, p-value: 0.4147
anova(Tol_Chl_M12_lm)
Analysis of Variance Table
Response: log(Chl.prop + 1)
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.004059 0.0040587 2.0575 0.1696
Genotype 2 0.002879 0.0014393 0.7296 0.4966
Site:Genotype 2 0.003545 0.0017723 0.8985 0.4257
Residuals 17 0.033534 0.0019726
#Effect Size of Predictors
eta_squared(Tol_Chl_M12_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.09 | [0.00, 1.00]
Genotype | 0.07 | [0.00, 1.00]
Site:Genotype | 0.08 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Chl_M12_lm.res<-data.frame(anova(Tol_Chl_M12_lm))
Tol_Chl_M12_lm.res$Predictor<-rownames(Tol_Chl_M12_lm.res)
Tol_Chl_M12_lm.res$EtaSq<-c(eta_squared(Tol_Chl_M12_lm, partial=FALSE)$Eta2, NA)
Tol_Chl_M12_lm.res$Response<-rep("Chlorophyll", nrow(Tol_Chl_M12_lm.res))
Tol_Chl_M12_lm.res$TimeP<-rep("M12", nrow(Tol_Chl_M12_lm.res))
Tol_Chl_M12_lm.res<-Tol_Chl_M12_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
No significant effects. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Chl_M12_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.0974 0.0222 17 0.0505 0.1442
AC12 0.0936 0.0222 17 0.0468 0.1405
AC8 0.0924 0.0222 17 0.0456 0.1393
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.0707 0.0222 17 0.0239 0.1176
AC12 0.0316 0.0256 17 -0.0225 0.0857
AC8 0.0923 0.0222 17 0.0454 0.1391
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.00377 0.0314 17 0.120 0.9921
AC10 - AC8 0.00497 0.0314 17 0.158 0.9863
AC12 - AC8 0.00121 0.0314 17 0.038 0.9992
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.03913 0.0339 17 1.154 0.4957
AC10 - AC8 -0.02158 0.0314 17 -0.687 0.7740
AC12 - AC8 -0.06071 0.0339 17 -1.790 0.2027
Note: contrasts are still on the log(mu + 1) scale
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Chl_M12_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.0974 0.0222 17 0.0505 0.1442
SS 0.0707 0.0222 17 0.0239 0.1176
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.0936 0.0222 17 0.0468 0.1405
SS 0.0316 0.0256 17 -0.0225 0.0857
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.0924 0.0222 17 0.0456 0.1393
SS 0.0923 0.0222 17 0.0454 0.1391
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.026684 0.0314 17 0.850 0.4073
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.062047 0.0339 17 1.829 0.0850
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.000126 0.0314 17 0.004 0.9969
Note: contrasts are still on the log(mu + 1) scale
##Save p-values
#Genotypes within Sites
Tol_Chl_M12_lm.geno<-data.frame(emmeans(Tol_Chl_M12_lm, pairwise~Genotype | Site)$contrasts)
Tol_Chl_M12_lm.geno<-Tol_Chl_M12_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M12_lm.geno$group1<-paste(Tol_Chl_M12_lm.geno$Site, Tol_Chl_M12_lm.geno$group1, sep="_")
Tol_Chl_M12_lm.geno$group2<-paste(Tol_Chl_M12_lm.geno$Site, Tol_Chl_M12_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Chl_M12_lm.site<-data.frame(emmeans(Tol_Chl_M12_lm, pairwise~Site | Genotype)$contrasts)
Tol_Chl_M12_lm.site<-Tol_Chl_M12_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Chl_M12_lm.site$group1<-paste(Tol_Chl_M12_lm.site$group1, Tol_Chl_M12_lm.site$Genotype, sep="_")
Tol_Chl_M12_lm.site$group2<-paste(Tol_Chl_M12_lm.site$group2, Tol_Chl_M12_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Chl_M12_lm.p<-rbind(Tol_Chl_M12_lm.geno[,c(1:2,4:8)], Tol_Chl_M12_lm.site[,c(1:2,4:8)])
Tol_Chl_M12_lm.p<-Tol_Chl_M12_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Chl_M12_lm.p$Sig<-ifelse(Tol_Chl_M12_lm.p$p<0.001, "***", ifelse(Tol_Chl_M12_lm.p$p<0.01, "**", ifelse(Tol_Chl_M12_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Chl_M12_lm.p$Response<-rep("Chlorophyll", nrow(Tol_Chl_M12_lm.p))
Tol_Chl_M12_lm.p$TimeP<-rep("M12", nrow(Tol_Chl_M12_lm.p))
##Summary statistics by Site and Genotype
Tol_Chl_M12_SG<-summarySE(TolData_M12, measurevar="Chl.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Chl_M12_SG.plot<-ggplot(Tol_Chl_M12_SG, aes(x=Site.Geno, y=Chl.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Chl.prop-se, ymax=Chl.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Chlorophyll Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o); Tol_Chl_M12_SG.plot
#+ stat_pvalue_manual(data=Tol_Chl_M12_lm.p, y.position=0.2, step.increase=0.20, label="Sig", hide.ns=TRUE) #No significant differences
##Check normality
hist(TolData$Sym.prop)
shapiro.test(TolData$Sym.prop)
Shapiro-Wilk normality test
data: TolData$Sym.prop
W = 0.91034, p-value = 9.046e-07
#Not Normal
##Try square transformation
hist((TolData$Sym.prop)^2)
shapiro.test((TolData$Sym.prop)^2)
Shapiro-Wilk normality test
data: (TolData$Sym.prop)^2
W = 0.86865, p-value = 9.119e-09
#Not normal
##Try cubed transformation
hist((TolData$Sym.prop)^3)
shapiro.test((TolData$Sym.prop)^3)
Shapiro-Wilk normality test
data: (TolData$Sym.prop)^3
W = 0.81677, p-value = 9.284e-11
#Not normal
##Model as a function of Site and Genotype and Timepoint
##Model with no transformation and check residuals
Tol_Sym_lm<-lm(Sym.prop~Site+Genotype+TimeP+ Site:Genotype + Site:TimeP + Genotype:TimeP, data=TolData)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Sym_lm)))
#Q-Q plot
qqnorm(resid(Tol_Sym_lm)); qqline(resid(Tol_Sym_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Sym_lm), resid(Tol_Sym_lm))
#Model Results
summary(Tol_Sym_lm)
Call:
lm(formula = Sym.prop ~ Site + Genotype + TimeP + Site:Genotype +
Site:TimeP + Genotype:TimeP, data = TolData)
Residuals:
Min 1Q Median 3Q Max
-0.39600 -0.09834 -0.01438 0.07946 0.42195
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.555690 0.013826 40.193 < 2e-16 ***
Site.L 0.009322 0.019517 0.478 0.634014
Genotype.L -0.226230 0.023747 -9.526 1.70e-15 ***
Genotype.Q 0.022268 0.024145 0.922 0.358711
TimeP.L -0.009548 0.030902 -0.309 0.758006
TimeP.Q -0.295353 0.030766 -9.600 1.18e-15 ***
TimeP.C -0.389767 0.031170 -12.504 < 2e-16 ***
TimeP^4 0.004264 0.030821 0.138 0.890261
Site.L:Genotype.L -0.046952 0.033584 -1.398 0.165353
Site.L:Genotype.Q 0.037992 0.034043 1.116 0.267229
Site.L:TimeP.L -0.063158 0.043658 -1.447 0.151286
Site.L:TimeP.Q 0.079465 0.043491 1.827 0.070814 .
Site.L:TimeP.C -0.073283 0.043949 -1.667 0.098716 .
Site.L:TimeP^4 -0.129699 0.043508 -2.981 0.003649 **
Genotype.L:TimeP.L 0.369878 0.053500 6.914 5.41e-10 ***
Genotype.Q:TimeP.L -0.039985 0.053547 -0.747 0.457073
Genotype.L:TimeP.Q 0.004050 0.053272 0.076 0.939565
Genotype.Q:TimeP.Q 0.044769 0.053306 0.840 0.403103
Genotype.L:TimeP.C -0.191475 0.052900 -3.620 0.000476 ***
Genotype.Q:TimeP.C 0.152684 0.055056 2.773 0.006681 **
Genotype.L:TimeP^4 -0.080152 0.052728 -1.520 0.131804
Genotype.Q:TimeP^4 -0.158952 0.054030 -2.942 0.004098 **
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1491 on 95 degrees of freedom
(23 observations deleted due to missingness)
Multiple R-squared: 0.8235, Adjusted R-squared: 0.7845
F-statistic: 21.11 on 21 and 95 DF, p-value: < 2.2e-16
anova(Tol_Sym_lm)
Analysis of Variance Table
Response: Sym.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.0097 0.00970 0.4367 0.510299
Genotype 2 1.9900 0.99498 44.7834 1.993e-14 ***
TimeP 4 5.5819 1.39547 62.8095 < 2.2e-16 ***
Site:Genotype 2 0.0709 0.03547 1.5965 0.208001
Site:TimeP 4 0.4045 0.10111 4.5511 0.002088 **
Genotype:TimeP 8 1.7916 0.22394 10.0797 4.424e-10 ***
Residuals 95 2.1107 0.02222
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Sym_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
----------------------------------------
Site | 8.11e-04 | [0.00, 1.00]
Genotype | 0.17 | [0.06, 1.00]
TimeP | 0.47 | [0.34, 1.00]
Site:Genotype | 5.93e-03 | [0.00, 1.00]
Site:TimeP | 0.03 | [0.00, 1.00]
Genotype:TimeP | 0.15 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Sym_lm.res<-data.frame(anova(Tol_Sym_lm))
Tol_Sym_lm.res$Predictor<-rownames(Tol_Sym_lm.res)
Tol_Sym_lm.res$EtaSq<-c(eta_squared(Tol_Sym_lm, partial=FALSE)$Eta2, NA)
Tol_Sym_lm.res$Response<-rep("Symbionts", nrow(Tol_Sym_lm.res))
Tol_Sym_lm.res<-Tol_Sym_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Strong influence of Timepoint, including interactions with main variables of interest, Site and Genotype. Will analyze each Timepoint individually.
Symbiont density was not measured at W1, starting with W2 for this response.
##Check normality
hist(TolData_W2$Sym.prop)
shapiro.test(TolData_W2$Sym.prop)
Shapiro-Wilk normality test
data: TolData_W2$Sym.prop
W = 0.93605, p-value = 0.1477
#Normal
##Model as a function of Site and Genotype
Tol_Sym_W2_lm<-lm(Sym.prop~Site+Genotype+Site:Genotype, data=TolData_W2)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Sym_W2_lm)))
#Q-Q plot
qqnorm(resid(Tol_Sym_W2_lm)); qqline(resid(Tol_Sym_W2_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Sym_W2_lm), resid(Tol_Sym_W2_lm))
#Model Results
summary(Tol_Sym_W2_lm)
Call:
lm(formula = Sym.prop ~ Site + Genotype + Site:Genotype, data = TolData_W2)
Residuals:
Min 1Q Median 3Q Max
-0.26060 -0.11145 0.00000 0.08525 0.28580
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.5237625 0.0325072 16.112 9.90e-12 ***
Site.L 0.0939568 0.0459722 2.044 0.0568 .
Genotype.L -0.4152131 0.0570402 -7.279 1.29e-06 ***
Genotype.Q -0.0005205 0.0555584 -0.009 0.9926
Site.L:Genotype.L -0.2061000 0.0806671 -2.555 0.0205 *
Site.L:Genotype.Q 0.0462891 0.0785715 0.589 0.5635
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.155 on 17 degrees of freedom
Multiple R-squared: 0.7924, Adjusted R-squared: 0.7313
F-statistic: 12.98 on 5 and 17 DF, p-value: 2.647e-05
anova(Tol_Sym_W2_lm)
Analysis of Variance Table
Response: Sym.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.16148 0.16148 6.7208 0.01897 *
Genotype 2 1.22843 0.61421 25.5640 7.508e-06 ***
Site:Genotype 2 0.16883 0.08441 3.5133 0.05283 .
Residuals 17 0.40845 0.02403
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Sym_W2_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.08 | [0.00, 1.00]
Genotype | 0.62 | [0.33, 1.00]
Site:Genotype | 0.09 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Sym_W2_lm.res<-data.frame(anova(Tol_Sym_W2_lm))
Tol_Sym_W2_lm.res$Predictor<-rownames(Tol_Sym_W2_lm.res)
Tol_Sym_W2_lm.res$EtaSq<-c(eta_squared(Tol_Sym_W2_lm, partial=FALSE)$Eta2, NA)
Tol_Sym_W2_lm.res$Response<-rep("Symbionts", nrow(Tol_Sym_W2_lm.res))
Tol_Sym_W2_lm.res$TimeP<-rep("W2", nrow(Tol_Sym_W2_lm.res))
Tol_Sym_W2_lm.res<-Tol_Sym_W2_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Marginal effect (p<0.1) of Site * Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Sym_W2_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.634 0.0775 17 0.4708 0.798
AC12 0.484 0.0775 17 0.3210 0.648
AC8 0.253 0.0775 17 0.0897 0.417
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 1.000 0.0775 17 0.8365 1.164
AC12 0.564 0.0775 17 0.4004 0.727
AC8 0.207 0.0895 17 0.0179 0.396
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.150 0.110 17 1.367 0.3795
AC10 - AC8 0.381 0.110 17 3.477 0.0077
AC12 - AC8 0.231 0.110 17 2.110 0.1174
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.436 0.110 17 3.979 0.0026
AC10 - AC8 0.793 0.118 17 6.701 <.0001
AC12 - AC8 0.357 0.118 17 3.017 0.0201
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Sym_W2_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.634 0.0775 17 0.4708 0.798
SS 1.000 0.0775 17 0.8365 1.164
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.484 0.0775 17 0.3210 0.648
SS 0.564 0.0775 17 0.4004 0.727
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.253 0.0775 17 0.0897 0.417
SS 0.207 0.0895 17 0.0179 0.396
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.3657 0.110 17 -3.337 0.0039
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0794 0.110 17 -0.725 0.4785
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.0465 0.118 17 0.393 0.6994
##Save p-values
#Genotypes within Sites
Tol_Sym_W2_lm.geno<-data.frame(emmeans(Tol_Sym_W2_lm, pairwise~Genotype | Site)$contrasts)
Tol_Sym_W2_lm.geno<-Tol_Sym_W2_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_W2_lm.geno$group1<-paste(Tol_Sym_W2_lm.geno$Site, Tol_Sym_W2_lm.geno$group1, sep="_")
Tol_Sym_W2_lm.geno$group2<-paste(Tol_Sym_W2_lm.geno$Site, Tol_Sym_W2_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Sym_W2_lm.site<-data.frame(emmeans(Tol_Sym_W2_lm, pairwise~Site | Genotype)$contrasts)
Tol_Sym_W2_lm.site<-Tol_Sym_W2_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_W2_lm.site$group1<-paste(Tol_Sym_W2_lm.site$group1, Tol_Sym_W2_lm.site$Genotype, sep="_")
Tol_Sym_W2_lm.site$group2<-paste(Tol_Sym_W2_lm.site$group2, Tol_Sym_W2_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Sym_W2_lm.p<-rbind(Tol_Sym_W2_lm.geno[,c(1:2,4:8)], Tol_Sym_W2_lm.site[,c(1:2,4:8)])
Tol_Sym_W2_lm.p<-Tol_Sym_W2_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Sym_W2_lm.p$Sig<-ifelse(Tol_Sym_W2_lm.p$p<0.001, "***", ifelse(Tol_Sym_W2_lm.p$p<0.01, "**", ifelse(Tol_Sym_W2_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Sym_W2_lm.p$Response<-rep("Symbionts", nrow(Tol_Sym_W2_lm.p))
Tol_Sym_W2_lm.p$TimeP<-rep("W2", nrow(Tol_Sym_W2_lm.p))
##Summary statistics by Site and Genotype
Tol_Sym_W2_SG<-summarySE(TolData_W2, measurevar="Sym.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Sym_W2_SG.plot<-ggplot(Tol_Sym_W2_SG, aes(x=Site.Geno, y=Sym.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Sym.prop-se, ymax=Sym.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Symbiont Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Sym_W2_lm.p, y.position=0.95, step.increase=0.15, label="Sig", hide.ns=TRUE); Tol_Sym_W2_SG.plot
##Check normality
hist(TolData_M1$Sym.prop)
shapiro.test(TolData_M1$Sym.prop)
Shapiro-Wilk normality test
data: TolData_M1$Sym.prop
W = 0.85748, p-value = 0.004618
#Not normal
##Try log+1 transformation
hist(log(TolData_M1$Sym.prop+1))
shapiro.test(log(TolData_M1$Sym.prop+1))
Shapiro-Wilk normality test
data: log(TolData_M1$Sym.prop + 1)
W = 0.87335, p-value = 0.009041
#Normal
##Model as a function of Site and Genotype
##Model with log transformation
Tol_Sym_M1_lm<-lm(log(Sym.prop+1)~Site+Genotype+Site:Genotype, data=TolData_M1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Sym_M1_lm)))
#Q-Q plot
qqnorm(resid(Tol_Sym_M1_lm)); qqline(resid(Tol_Sym_M1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Sym_M1_lm), resid(Tol_Sym_M1_lm))
#Model Results
summary(Tol_Sym_M1_lm)
Call:
lm(formula = log(Sym.prop + 1) ~ Site + Genotype + Site:Genotype,
data = TolData_M1)
Residuals:
Min 1Q Median 3Q Max
-0.098079 -0.055799 -0.004888 0.043331 0.151113
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.307716 0.016556 18.587 2.95e-12 ***
Site.L 0.027767 0.023413 1.186 0.252954
Genotype.L -0.295494 0.027204 -10.862 8.59e-09 ***
Genotype.Q 0.129387 0.030075 4.302 0.000548 ***
Site.L:Genotype.L 0.080682 0.038472 2.097 0.052224 .
Site.L:Genotype.Q -0.005572 0.042532 -0.131 0.897412
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.07694 on 16 degrees of freedom
Multiple R-squared: 0.8989, Adjusted R-squared: 0.8673
F-statistic: 28.46 on 5 and 16 DF, p-value: 2e-07
anova(Tol_Sym_M1_lm)
Analysis of Variance Table
Response: log(Sym.prop + 1)
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.00823 0.00823 1.3902 0.2556
Genotype 2 0.80811 0.40406 68.2486 1.468e-08 ***
Site:Genotype 2 0.02614 0.01307 2.2076 0.1423
Residuals 16 0.09473 0.00592
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Sym_M1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 8.78e-03 | [0.00, 1.00]
Genotype | 0.86 | [0.73, 1.00]
Site:Genotype | 0.03 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Sym_M1_lm.res<-data.frame(anova(Tol_Sym_M1_lm))
Tol_Sym_M1_lm.res$Predictor<-rownames(Tol_Sym_M1_lm.res)
Tol_Sym_M1_lm.res$EtaSq<-c(eta_squared(Tol_Sym_M1_lm, partial=FALSE)$Eta2, NA)
Tol_Sym_M1_lm.res$Response<-rep("Symbionts", nrow(Tol_Sym_M1_lm.res))
Tol_Sym_M1_lm.res$TimeP<-rep("M1", nrow(Tol_Sym_M1_lm.res))
Tol_Sym_M1_lm.res<-Tol_Sym_M1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Sym_M1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.5918 0.0385 16 0.5102 0.673
AC12 0.1792 0.0444 16 0.0850 0.273
AC8 0.0932 0.0385 16 0.0117 0.175
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.5472 0.0385 16 0.4656 0.629
AC12 0.2249 0.0444 16 0.1307 0.319
AC8 0.2100 0.0385 16 0.1284 0.292
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.413 0.0588 16 7.021 <.0001
AC10 - AC8 0.499 0.0544 16 9.164 <.0001
AC12 - AC8 0.086 0.0588 16 1.463 0.3339
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.322 0.0588 16 5.483 0.0001
AC10 - AC8 0.337 0.0544 16 6.198 <.0001
AC12 - AC8 0.015 0.0588 16 0.255 0.9650
Note: contrasts are still on the log(mu + 1) scale
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Sym_M1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.5918 0.0385 16 0.5102 0.673
SS 0.5472 0.0385 16 0.4656 0.629
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.1792 0.0444 16 0.0850 0.273
SS 0.2249 0.0444 16 0.1307 0.319
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.0932 0.0385 16 0.0117 0.175
SS 0.2100 0.0385 16 0.1284 0.292
Results are given on the log(mu + 1) (not the response) scale.
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.0446 0.0544 16 0.820 0.4241
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0457 0.0628 16 -0.727 0.4775
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.1167 0.0544 16 -2.146 0.0476
Note: contrasts are still on the log(mu + 1) scale
##Save p-values
#Genotypes within Sites
Tol_Sym_M1_lm.geno<-data.frame(emmeans(Tol_Sym_M1_lm, pairwise~Genotype | Site)$contrasts)
Tol_Sym_M1_lm.geno<-Tol_Sym_M1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M1_lm.geno$group1<-paste(Tol_Sym_M1_lm.geno$Site, Tol_Sym_M1_lm.geno$group1, sep="_")
Tol_Sym_M1_lm.geno$group2<-paste(Tol_Sym_M1_lm.geno$Site, Tol_Sym_M1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Sym_M1_lm.site<-data.frame(emmeans(Tol_Sym_M1_lm, pairwise~Site | Genotype)$contrasts)
Tol_Sym_M1_lm.site<-Tol_Sym_M1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M1_lm.site$group1<-paste(Tol_Sym_M1_lm.site$group1, Tol_Sym_M1_lm.site$Genotype, sep="_")
Tol_Sym_M1_lm.site$group2<-paste(Tol_Sym_M1_lm.site$group2, Tol_Sym_M1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Sym_M1_lm.p<-rbind(Tol_Sym_M1_lm.geno[,c(1:2,4:8)], Tol_Sym_M1_lm.site[,c(1:2,4:8)])
Tol_Sym_M1_lm.p<-Tol_Sym_M1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Sym_M1_lm.p$Sig<-ifelse(Tol_Sym_M1_lm.p$p<0.001, "***", ifelse(Tol_Sym_M1_lm.p$p<0.01, "**", ifelse(Tol_Sym_M1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Sym_M1_lm.p$Response<-rep("Symbionts", nrow(Tol_Sym_M1_lm.p))
Tol_Sym_M1_lm.p$TimeP<-rep("M1", nrow(Tol_Sym_M1_lm.p))
##Summary statistics by Site and Genotype
Tol_Sym_M1_SG<-summarySE(TolData_M1, measurevar="Sym.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Sym_M1_SG.plot<-ggplot(Tol_Sym_M1_SG, aes(x=Site.Geno, y=Sym.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Sym.prop-se, ymax=Sym.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Symbiont Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Sym_M1_lm.p, y.position=0.95, step.increase=0.15, label="Sig", hide.ns=TRUE); Tol_Sym_M1_SG.plot
##Check normality
hist(TolData_M4$Sym.prop)
shapiro.test(TolData_M4$Sym.prop)
Shapiro-Wilk normality test
data: TolData_M4$Sym.prop
W = 0.88557, p-value = 0.01078
#Not Normal
##Try square transformation
hist((TolData_M4$Sym.prop)^2)
shapiro.test((TolData_M4$Sym.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M4$Sym.prop)^2
W = 0.87973, p-value = 0.008208
#Not Normal
##Try cubed transformation
hist((TolData_M4$Sym.prop)^3)
shapiro.test((TolData_M4$Sym.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M4$Sym.prop)^3
W = 0.8488, p-value = 0.002077
#Not Normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_Sym_M4_lm<-lm(Sym.prop~Site+Genotype+Site:Genotype, data=TolData_M4)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Sym_M4_lm)))
#Q-Q plot
qqnorm(resid(Tol_Sym_M4_lm)); qqline(resid(Tol_Sym_M4_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Sym_M4_lm), resid(Tol_Sym_M4_lm))
#Model Results
summary(Tol_Sym_M4_lm)
Call:
lm(formula = Sym.prop ~ Site + Genotype + Site:Genotype, data = TolData_M4)
Residuals:
Min 1Q Median 3Q Max
-0.31820 -0.08804 0.00000 0.08618 0.29740
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.71662 0.03157 22.702 1.07e-14 ***
Site.L -0.12617 0.04464 -2.826 0.0112 *
Genotype.L -0.28587 0.05467 -5.229 5.67e-05 ***
Genotype.Q -0.11565 0.05467 -2.115 0.0486 *
Site.L:Genotype.L -0.09494 0.07732 -1.228 0.2353
Site.L:Genotype.Q 0.17275 0.07732 2.234 0.0384 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1546 on 18 degrees of freedom
Multiple R-squared: 0.7201, Adjusted R-squared: 0.6423
F-statistic: 9.26 on 5 and 18 DF, p-value: 0.0001686
anova(Tol_Sym_M4_lm)
Analysis of Variance Table
Response: Sym.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.19101 0.19101 7.9874 0.011190 *
Genotype 2 0.76080 0.38040 15.9068 0.000105 ***
Site:Genotype 2 0.15542 0.07771 3.2496 0.062386 .
Residuals 18 0.43046 0.02391
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Sym_M4_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.12 | [0.00, 1.00]
Genotype | 0.49 | [0.18, 1.00]
Site:Genotype | 0.10 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Sym_M4_lm.res<-data.frame(anova(Tol_Sym_M4_lm))
Tol_Sym_M4_lm.res$Predictor<-rownames(Tol_Sym_M4_lm.res)
Tol_Sym_M4_lm.res$EtaSq<-c(eta_squared(Tol_Sym_M4_lm, partial=FALSE)$Eta2, NA)
Tol_Sym_M4_lm.res$Response<-rep("Symbionts", nrow(Tol_Sym_M4_lm.res))
Tol_Sym_M4_lm.res$TimeP<-rep("M4", nrow(Tol_Sym_M4_lm.res))
Tol_Sym_M4_lm.res<-Tol_Sym_M4_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Marginal effect (p<0.1) of Site * Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Sym_M4_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.863 0.0773 18 0.701 1.026
AC12 1.000 0.0773 18 0.838 1.162
AC8 0.554 0.0773 18 0.392 0.717
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.880 0.0773 18 0.717 1.042
AC12 0.622 0.0773 18 0.460 0.785
AC8 0.380 0.0773 18 0.218 0.543
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.137 0.109 18 -1.249 0.4409
AC10 - AC8 0.309 0.109 18 2.829 0.0285
AC12 - AC8 0.446 0.109 18 4.078 0.0019
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.258 0.109 18 2.356 0.0734
AC10 - AC8 0.499 0.109 18 4.565 0.0007
AC12 - AC8 0.242 0.109 18 2.210 0.0965
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Sym_M4_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.863 0.0773 18 0.701 1.026
SS 0.880 0.0773 18 0.717 1.042
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 1.000 0.0773 18 0.838 1.162
SS 0.622 0.0773 18 0.460 0.785
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.554 0.0773 18 0.392 0.717
SS 0.380 0.0773 18 0.218 0.543
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0163 0.109 18 -0.149 0.8835
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.3779 0.109 18 3.456 0.0028
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.1736 0.109 18 1.588 0.1297
##Save p-values
#Genotypes within Sites
Tol_Sym_M4_lm.geno<-data.frame(emmeans(Tol_Sym_M4_lm, pairwise~Genotype | Site)$contrasts)
Tol_Sym_M4_lm.geno<-Tol_Sym_M4_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M4_lm.geno$group1<-paste(Tol_Sym_M4_lm.geno$Site, Tol_Sym_M4_lm.geno$group1, sep="_")
Tol_Sym_M4_lm.geno$group2<-paste(Tol_Sym_M4_lm.geno$Site, Tol_Sym_M4_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Sym_M4_lm.site<-data.frame(emmeans(Tol_Sym_M4_lm, pairwise~Site | Genotype)$contrasts)
Tol_Sym_M4_lm.site<-Tol_Sym_M4_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M4_lm.site$group1<-paste(Tol_Sym_M4_lm.site$group1, Tol_Sym_M4_lm.site$Genotype, sep="_")
Tol_Sym_M4_lm.site$group2<-paste(Tol_Sym_M4_lm.site$group2, Tol_Sym_M4_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Sym_M4_lm.p<-rbind(Tol_Sym_M4_lm.geno[,c(1:2,4:8)], Tol_Sym_M4_lm.site[,c(1:2,4:8)])
Tol_Sym_M4_lm.p<-Tol_Sym_M4_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Sym_M4_lm.p$Sig<-ifelse(Tol_Sym_M4_lm.p$p<0.001, "***", ifelse(Tol_Sym_M4_lm.p$p<0.01, "**", ifelse(Tol_Sym_M4_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Sym_M4_lm.p$Response<-rep("Symbionts", nrow(Tol_Sym_M4_lm.p))
Tol_Sym_M4_lm.p$TimeP<-rep("M4", nrow(Tol_Sym_M4_lm.p))
##Summary statistics by Site and Genotype
Tol_Sym_M4_SG<-summarySE(TolData_M4, measurevar="Sym.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Sym_M4_SG.plot<-ggplot(Tol_Sym_M4_SG, aes(x=Site.Geno, y=Sym.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Sym.prop-se, ymax=Sym.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Symbiont Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Sym_M4_lm.p, y.position=1.1, step.increase=0.15, label="Sig", hide.ns=TRUE); Tol_Sym_M4_SG.plot
##Check normality
hist(TolData_M8$Sym.prop)
shapiro.test(TolData_M8$Sym.prop)
Shapiro-Wilk normality test
data: TolData_M8$Sym.prop
W = 0.88171, p-value = 0.008995
#Not Normal
##Try square transformation
hist((TolData_M8$Sym.prop)^2)
shapiro.test((TolData_M8$Sym.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M8$Sym.prop)^2
W = 0.88024, p-value = 0.008402
#Not Normal
##Try cubed transformation
hist((TolData_M8$Sym.prop)^3)
shapiro.test((TolData_M8$Sym.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M8$Sym.prop)^3
W = 0.8729, p-value = 0.005999
#Not Normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_Sym_M8_lm<-lm(Sym.prop~Site+Genotype+Site:Genotype, data=TolData_M8)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Sym_M8_lm)))
#Q-Q plot
qqnorm(resid(Tol_Sym_M8_lm)); qqline(resid(Tol_Sym_M8_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Sym_M8_lm), resid(Tol_Sym_M8_lm))
#Model Results
summary(Tol_Sym_M8_lm)
Call:
lm(formula = Sym.prop ~ Site + Genotype + Site:Genotype, data = TolData_M8)
Residuals:
Min 1Q Median 3Q Max
-0.157800 -0.050981 0.001975 0.059175 0.151250
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.87608 0.01989 44.048 <2e-16 ***
Site.L 0.07647 0.02813 2.719 0.0141 *
Genotype.L 0.04907 0.03445 1.425 0.1714
Genotype.Q -0.02291 0.03445 -0.665 0.5144
Site.L:Genotype.L -0.11457 0.04872 -2.352 0.0303 *
Site.L:Genotype.Q 0.01391 0.04872 0.286 0.7784
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.09744 on 18 degrees of freedom
Multiple R-squared: 0.4623, Adjusted R-squared: 0.3129
F-statistic: 3.095 on 5 and 18 DF, p-value: 0.03448
anova(Tol_Sym_M8_lm)
Analysis of Variance Table
Response: Sym.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.070168 0.070168 7.3908 0.01408 *
Genotype 2 0.023465 0.011733 1.2358 0.31411
Site:Genotype 2 0.053284 0.026642 2.8062 0.08693 .
Residuals 18 0.170890 0.009494
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_Sym_M8_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.22 | [0.01, 1.00]
Genotype | 0.07 | [0.00, 1.00]
Site:Genotype | 0.17 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Sym_M8_lm.res<-data.frame(anova(Tol_Sym_M8_lm))
Tol_Sym_M8_lm.res$Predictor<-rownames(Tol_Sym_M8_lm.res)
Tol_Sym_M8_lm.res$EtaSq<-c(eta_squared(Tol_Sym_M8_lm, partial=FALSE)$Eta2, NA)
Tol_Sym_M8_lm.res$Response<-rep("Symbionts", nrow(Tol_Sym_M8_lm.res))
Tol_Sym_M8_lm.res$TimeP<-rep("M8", nrow(Tol_Sym_M8_lm.res))
Tol_Sym_M8_lm.res<-Tol_Sym_M8_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site. Marginal effect (p<0.1) of Site * Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Sym_M8_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.717 0.0487 18 0.614 0.819
AC12 0.849 0.0487 18 0.746 0.951
AC8 0.901 0.0487 18 0.798 1.003
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.947 0.0487 18 0.845 1.050
AC12 0.941 0.0487 18 0.838 1.043
AC8 0.902 0.0487 18 0.800 1.005
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.13210 0.0689 18 -1.917 0.1626
AC10 - AC8 -0.18397 0.0689 18 -2.670 0.0395
AC12 - AC8 -0.05187 0.0689 18 -0.753 0.7358
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.00658 0.0689 18 0.095 0.9950
AC10 - AC8 0.04517 0.0689 18 0.656 0.7916
AC12 - AC8 0.03860 0.0689 18 0.560 0.8426
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Sym_M8_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.717 0.0487 18 0.614 0.819
SS 0.947 0.0487 18 0.845 1.050
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.849 0.0487 18 0.746 0.951
SS 0.941 0.0487 18 0.838 1.043
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.901 0.0487 18 0.798 1.003
SS 0.902 0.0487 18 0.800 1.005
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.2308 0.0689 18 -3.349 0.0036
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0921 0.0689 18 -1.336 0.1981
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0016 0.0689 18 -0.023 0.9817
##Save p-values
#Genotypes within Sites
Tol_Sym_M8_lm.geno<-data.frame(emmeans(Tol_Sym_M8_lm, pairwise~Genotype | Site)$contrasts)
Tol_Sym_M8_lm.geno<-Tol_Sym_M8_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M8_lm.geno$group1<-paste(Tol_Sym_M8_lm.geno$Site, Tol_Sym_M8_lm.geno$group1, sep="_")
Tol_Sym_M8_lm.geno$group2<-paste(Tol_Sym_M8_lm.geno$Site, Tol_Sym_M8_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Sym_M8_lm.site<-data.frame(emmeans(Tol_Sym_M8_lm, pairwise~Site | Genotype)$contrasts)
Tol_Sym_M8_lm.site<-Tol_Sym_M8_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M8_lm.site$group1<-paste(Tol_Sym_M8_lm.site$group1, Tol_Sym_M8_lm.site$Genotype, sep="_")
Tol_Sym_M8_lm.site$group2<-paste(Tol_Sym_M8_lm.site$group2, Tol_Sym_M8_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Sym_M8_lm.p<-rbind(Tol_Sym_M8_lm.geno[,c(1:2,4:8)], Tol_Sym_M8_lm.site[,c(1:2,4:8)])
Tol_Sym_M8_lm.p<-Tol_Sym_M8_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Sym_M8_lm.p$Sig<-ifelse(Tol_Sym_M8_lm.p$p<0.001, "***", ifelse(Tol_Sym_M8_lm.p$p<0.01, "**", ifelse(Tol_Sym_M8_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Sym_M8_lm.p$Response<-rep("Symbionts", nrow(Tol_Sym_M8_lm.p))
Tol_Sym_M8_lm.p$TimeP<-rep("M8", nrow(Tol_Sym_M8_lm.p))
##Summary statistics by Site and Genotype
Tol_Sym_M8_SG<-summarySE(TolData_M8, measurevar="Sym.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Sym_M8_SG.plot<-ggplot(Tol_Sym_M8_SG, aes(x=Site.Geno, y=Sym.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Sym.prop-se, ymax=Sym.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Symbiont Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_Sym_M8_lm.p, y.position=1.05, step.increase=0.4, label="Sig", hide.ns=TRUE); Tol_Sym_M8_SG.plot
##Check normality
hist(TolData_M12$Sym.prop)
shapiro.test(TolData_M12$Sym.prop)
Shapiro-Wilk normality test
data: TolData_M12$Sym.prop
W = 0.9228, p-value = 0.06737
#Normal
##Model as a function of Site and Genotype
Tol_Sym_M12_lm<-lm(Sym.prop~Site+Genotype+Site:Genotype, data=TolData_M12)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_Sym_M12_lm)))
#Q-Q plot
qqnorm(resid(Tol_Sym_M12_lm)); qqline(resid(Tol_Sym_M12_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_Sym_M12_lm), resid(Tol_Sym_M12_lm))
#Model Results
summary(Tol_Sym_M12_lm)
Call:
lm(formula = Sym.prop ~ Site + Genotype + Site:Genotype, data = TolData_M12)
Residuals:
Min 1Q Median 3Q Max
-0.17948 -0.12040 -0.02149 0.05658 0.37585
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.26903 0.03512 7.660 4.52e-07 ***
Site.L -0.02682 0.04967 -0.540 0.596
Genotype.L -0.06026 0.06083 -0.991 0.335
Genotype.Q 0.05019 0.06083 0.825 0.420
Site.L:Genotype.L 0.06158 0.08603 0.716 0.483
Site.L:Genotype.Q -0.04186 0.08603 -0.487 0.632
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1721 on 18 degrees of freedom
Multiple R-squared: 0.1305, Adjusted R-squared: -0.111
F-statistic: 0.5405 on 5 and 18 DF, p-value: 0.7432
anova(Tol_Sym_M12_lm)
Analysis of Variance Table
Response: Sym.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.00863 0.0086336 0.2916 0.5958
Genotype 2 0.04921 0.0246044 0.8311 0.4516
Site:Genotype 2 0.02217 0.0110871 0.3745 0.6929
Residuals 18 0.53291 0.0296063
#Effect Size of Predictors
eta_squared(Tol_Sym_M12_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.01 | [0.00, 1.00]
Genotype | 0.08 | [0.00, 1.00]
Site:Genotype | 0.04 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_Sym_M12_lm.res<-data.frame(anova(Tol_Sym_M12_lm))
Tol_Sym_M12_lm.res$Predictor<-rownames(Tol_Sym_M12_lm.res)
Tol_Sym_M12_lm.res$EtaSq<-c(eta_squared(Tol_Sym_M12_lm, partial=FALSE)$Eta2, NA)
Tol_Sym_M12_lm.res$Response<-rep("Symbionts", nrow(Tol_Sym_M12_lm.res))
Tol_Sym_M12_lm.res$TimeP<-rep("M12", nrow(Tol_Sym_M12_lm.res))
Tol_Sym_M12_lm.res<-Tol_Sym_M12_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
No significant effects of Site or Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_Sym_M12_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.394 0.086 18 0.2132 0.575
AC12 0.223 0.086 18 0.0421 0.404
AC8 0.247 0.086 18 0.0664 0.428
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.270 0.086 18 0.0896 0.451
AC12 0.233 0.086 18 0.0525 0.414
AC8 0.247 0.086 18 0.0659 0.427
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1711 0.122 18 1.406 0.3586
AC10 - AC8 0.1468 0.122 18 1.207 0.4646
AC12 - AC8 -0.0243 0.122 18 -0.200 0.9782
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0370 0.122 18 0.305 0.9503
AC10 - AC8 0.0237 0.122 18 0.194 0.9794
AC12 - AC8 -0.0134 0.122 18 -0.110 0.9933
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_Sym_M12_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.394 0.086 18 0.2132 0.575
SS 0.270 0.086 18 0.0896 0.451
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.223 0.086 18 0.0421 0.404
SS 0.233 0.086 18 0.0525 0.414
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.247 0.086 18 0.0664 0.428
SS 0.247 0.086 18 0.0659 0.427
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.123675 0.122 18 1.016 0.3229
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.010400 0.122 18 -0.085 0.9328
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.000525 0.122 18 0.004 0.9966
##Save p-values
#Genotypes within Sites
Tol_Sym_M12_lm.geno<-data.frame(emmeans(Tol_Sym_M12_lm, pairwise~Genotype | Site)$contrasts)
Tol_Sym_M12_lm.geno<-Tol_Sym_M12_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M12_lm.geno$group1<-paste(Tol_Sym_M12_lm.geno$Site, Tol_Sym_M12_lm.geno$group1, sep="_")
Tol_Sym_M12_lm.geno$group2<-paste(Tol_Sym_M12_lm.geno$Site, Tol_Sym_M12_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_Sym_M12_lm.site<-data.frame(emmeans(Tol_Sym_M12_lm, pairwise~Site | Genotype)$contrasts)
Tol_Sym_M12_lm.site<-Tol_Sym_M12_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_Sym_M12_lm.site$group1<-paste(Tol_Sym_M12_lm.site$group1, Tol_Sym_M12_lm.site$Genotype, sep="_")
Tol_Sym_M12_lm.site$group2<-paste(Tol_Sym_M12_lm.site$group2, Tol_Sym_M12_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_Sym_M12_lm.p<-rbind(Tol_Sym_M12_lm.geno[,c(1:2,4:8)], Tol_Sym_M12_lm.site[,c(1:2,4:8)])
Tol_Sym_M12_lm.p<-Tol_Sym_M12_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_Sym_M12_lm.p$Sig<-ifelse(Tol_Sym_M12_lm.p$p<0.001, "***", ifelse(Tol_Sym_M12_lm.p$p<0.01, "**", ifelse(Tol_Sym_M12_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_Sym_M12_lm.p$Response<-rep("Symbionts", nrow(Tol_Sym_M12_lm.p))
Tol_Sym_M12_lm.p$TimeP<-rep("M12", nrow(Tol_Sym_M12_lm.p))
##Summary statistics by Site and Genotype
Tol_Sym_M12_SG<-summarySE(TolData_M12, measurevar="Sym.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_Sym_M12_SG.plot<-ggplot(Tol_Sym_M12_SG, aes(x=Site.Geno, y=Sym.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Sym.prop-se, ymax=Sym.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Symbiont Retention")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o); Tol_Sym_M12_SG.plot
#+ stat_pvalue_manual(data=Tol_Sym_M12_lm.p, y.position=0.95, step.increase=0.15, label="Sig", hide.ns=TRUE) #No significant differences
##Check normality
hist(TolData$Score_Full.prop)
shapiro.test(TolData$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData$Score_Full.prop
W = 0.90787, p-value = 8.714e-08
#Not Normal
##Try square transformation
hist((TolData$Score_Full.prop)^2)
shapiro.test((TolData$Score_Full.prop)^2)
Shapiro-Wilk normality test
data: (TolData$Score_Full.prop)^2
W = 0.90167, p-value = 3.893e-08
#Not normal
##Try cubed transformation
hist((TolData$Score_Full.prop)^3)
shapiro.test((TolData$Score_Full.prop)^3)
Shapiro-Wilk normality test
data: (TolData$Score_Full.prop)^3
W = 0.87565, p-value = 1.792e-09
#Not normal
##Model as a function of Site and Genotype and Timepoint
##Model with no transformation and check residuals
Tol_ScoreF_lm<-lm(Score_Full.prop~Site+Genotype+TimeP+ Site:Genotype + Site:TimeP + Genotype:TimeP, data=TolData)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_lm)); qqline(resid(Tol_ScoreF_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_lm), resid(Tol_ScoreF_lm))
Residuals are not great, need to check for other modeling options for Color Full Set.
#Model Results
summary(Tol_ScoreF_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + TimeP + Site:Genotype +
Site:TimeP + Genotype:TimeP, data = TolData)
Residuals:
Min 1Q Median 3Q Max
-0.39018 -0.04431 -0.00316 0.05485 0.44471
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.714814 0.011766 60.755 < 2e-16 ***
Site.L 0.057324 0.016618 3.449 0.000788 ***
Genotype.L -0.165762 0.020155 -8.224 3.54e-13 ***
Genotype.Q -0.017805 0.020604 -0.864 0.389333
TimeP.L 0.172504 0.028691 6.012 2.25e-08 ***
TimeP.Q -0.286969 0.028843 -9.950 < 2e-16 ***
TimeP.C -0.224989 0.028759 -7.823 2.86e-12 ***
TimeP^4 -0.071363 0.028803 -2.478 0.014693 *
TimeP^5 -0.053084 0.029014 -1.830 0.069924 .
Site.L:Genotype.L 0.030948 0.028503 1.086 0.279871
Site.L:Genotype.Q -0.001701 0.029078 -0.059 0.953441
Site.L:TimeP.L -0.074957 0.040574 -1.847 0.067277 .
Site.L:TimeP.Q -0.045864 0.040708 -1.127 0.262255
Site.L:TimeP.C 0.054853 0.040629 1.350 0.179657
Site.L:TimeP^4 -0.021594 0.040696 -0.531 0.596720
Site.L:TimeP^5 0.003590 0.040907 0.088 0.930220
Genotype.L:TimeP.L 0.277820 0.049298 5.635 1.28e-07 ***
Genotype.Q:TimeP.L 0.080240 0.050101 1.602 0.112021
Genotype.L:TimeP.Q 0.030629 0.049080 0.624 0.533835
Genotype.Q:TimeP.Q -0.084229 0.050814 -1.658 0.100149
Genotype.L:TimeP.C -0.034948 0.049565 -0.705 0.482187
Genotype.Q:TimeP.C 0.051244 0.050045 1.024 0.308025
Genotype.L:TimeP^4 -0.046076 0.049656 -0.928 0.355418
Genotype.Q:TimeP^4 0.078285 0.050113 1.562 0.121017
Genotype.L:TimeP^5 -0.034519 0.049244 -0.701 0.484742
Genotype.Q:TimeP^5 -0.107154 0.051244 -2.091 0.038745 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1388 on 114 degrees of freedom
Multiple R-squared: 0.7526, Adjusted R-squared: 0.6983
F-statistic: 13.87 on 25 and 114 DF, p-value: < 2.2e-16
anova(Tol_ScoreF_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.2584 0.25839 13.4204 0.0003791 ***
Genotype 2 1.2851 0.64255 33.3728 3.897e-12 ***
TimeP 5 4.0800 0.81599 42.3811 < 2.2e-16 ***
Site:Genotype 2 0.0245 0.01226 0.6365 0.5309976
Site:TimeP 5 0.1431 0.02862 1.4863 0.1997489
Genotype:TimeP 10 0.8845 0.08845 4.5940 1.761e-05 ***
Residuals 114 2.1949 0.01925
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreF_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
----------------------------------------
Site | 0.03 | [0.00, 1.00]
Genotype | 0.14 | [0.05, 1.00]
TimeP | 0.46 | [0.34, 1.00]
Site:Genotype | 2.76e-03 | [0.00, 1.00]
Site:TimeP | 0.02 | [0.00, 1.00]
Genotype:TimeP | 0.10 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_lm.res<-data.frame(anova(Tol_ScoreF_lm))
Tol_ScoreF_lm.res$Predictor<-rownames(Tol_ScoreF_lm.res)
Tol_ScoreF_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_lm.res))
Tol_ScoreF_lm.res<-Tol_ScoreF_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Strong influence of Timepoint, including interactions with Genotype. Will analyze each Timepoint individually.
##Check normality
hist(TolData_W1$Score_Full.prop)
shapiro.test(TolData_W1$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData_W1$Score_Full.prop
W = 0.96698, p-value = 0.6172
#Normal
##Model as a function of Site and Genotype
Tol_ScoreF_W1_lm<-lm(Score_Full.prop~Site+Genotype+Site:Genotype, data=TolData_W1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_W1_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_W1_lm)); qqline(resid(Tol_ScoreF_W1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_W1_lm), resid(Tol_ScoreF_W1_lm))
#Model Results
summary(Tol_ScoreF_W1_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + Site:Genotype,
data = TolData_W1)
Residuals:
Min 1Q Median 3Q Max
-0.25028 -0.08754 0.01292 0.07720 0.40030
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.52653 0.03678 14.314 6.49e-11 ***
Site.L 0.04903 0.05202 0.942 0.359175
Genotype.L -0.30859 0.06201 -4.976 0.000115 ***
Genotype.Q -0.10351 0.06537 -1.583 0.131744
Site.L:Genotype.L 0.02654 0.08770 0.303 0.765870
Site.L:Genotype.Q 0.07968 0.09244 0.862 0.400713
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1754 on 17 degrees of freedom
Multiple R-squared: 0.6322, Adjusted R-squared: 0.524
F-statistic: 5.844 on 5 and 17 DF, p-value: 0.002556
anova(Tol_ScoreF_W1_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.02487 0.02487 0.8085 0.3811294
Genotype 2 0.84845 0.42423 13.7892 0.0002762 ***
Site:Genotype 2 0.02567 0.01284 0.4173 0.6654183
Residuals 17 0.52301 0.03077
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreF_W1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.02 | [0.00, 1.00]
Genotype | 0.60 | [0.29, 1.00]
Site:Genotype | 0.02 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_W1_lm.res<-data.frame(anova(Tol_ScoreF_W1_lm))
Tol_ScoreF_W1_lm.res$Predictor<-rownames(Tol_ScoreF_W1_lm.res)
Tol_ScoreF_W1_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_W1_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_W1_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_W1_lm.res))
Tol_ScoreF_W1_lm.res$TimeP<-rep("W1", nrow(Tol_ScoreF_W1_lm.res))
Tol_ScoreF_W1_lm.res<-Tol_ScoreF_W1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreF_W1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.658 0.0877 17 0.4730 0.843
AC12 0.622 0.0877 17 0.4373 0.807
AC8 0.195 0.0877 17 0.0101 0.380
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.747 0.0877 17 0.5618 0.932
AC12 0.600 0.1013 17 0.3860 0.813
AC8 0.337 0.0877 17 0.1520 0.522
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0357 0.124 17 0.288 0.9555
AC10 - AC8 0.4629 0.124 17 3.733 0.0045
AC12 - AC8 0.4273 0.124 17 3.445 0.0082
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1472 0.134 17 1.099 0.5278
AC10 - AC8 0.4099 0.124 17 3.305 0.0111
AC12 - AC8 0.2627 0.134 17 1.961 0.1524
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreF_W1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.658 0.0877 17 0.4730 0.843
SS 0.747 0.0877 17 0.5618 0.932
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.622 0.0877 17 0.4373 0.807
SS 0.600 0.1013 17 0.3860 0.813
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.195 0.0877 17 0.0101 0.380
SS 0.337 0.0877 17 0.1520 0.522
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0888 0.124 17 -0.716 0.4837
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.0227 0.134 17 0.169 0.8676
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.1419 0.124 17 -1.144 0.2685
##Save p-values
#Genotypes within Sites
Tol_ScoreF_W1_lm.geno<-data.frame(emmeans(Tol_ScoreF_W1_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreF_W1_lm.geno<-Tol_ScoreF_W1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_W1_lm.geno$group1<-paste(Tol_ScoreF_W1_lm.geno$Site, Tol_ScoreF_W1_lm.geno$group1, sep="_")
Tol_ScoreF_W1_lm.geno$group2<-paste(Tol_ScoreF_W1_lm.geno$Site, Tol_ScoreF_W1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreF_W1_lm.site<-data.frame(emmeans(Tol_ScoreF_W1_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreF_W1_lm.site<-Tol_ScoreF_W1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_W1_lm.site$group1<-paste(Tol_ScoreF_W1_lm.site$group1, Tol_ScoreF_W1_lm.site$Genotype, sep="_")
Tol_ScoreF_W1_lm.site$group2<-paste(Tol_ScoreF_W1_lm.site$group2, Tol_ScoreF_W1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreF_W1_lm.p<-rbind(Tol_ScoreF_W1_lm.geno[,c(1:2,4:8)], Tol_ScoreF_W1_lm.site[,c(1:2,4:8)])
Tol_ScoreF_W1_lm.p<-Tol_ScoreF_W1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreF_W1_lm.p$Sig<-ifelse(Tol_ScoreF_W1_lm.p$p<0.001, "***", ifelse(Tol_ScoreF_W1_lm.p$p<0.01, "**", ifelse(Tol_ScoreF_W1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreF_W1_lm.p$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_W1_lm.p))
Tol_ScoreF_W1_lm.p$TimeP<-rep("W1", nrow(Tol_ScoreF_W1_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreF_W1_SG<-summarySE(TolData_W1, measurevar="Score_Full.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreF_W1_SG.plot<-ggplot(Tol_ScoreF_W1_SG, aes(x=Site.Geno, y=Score_Full.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_Full.prop-se, ymax=Score_Full.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention Full Set")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreF_W1_lm.p, y.position=0.80, step.increase=0.2, label="Sig", hide.ns=TRUE); Tol_ScoreF_W1_SG.plot
##Check normality
hist(TolData_W2$Score_Full.prop)
shapiro.test(TolData_W2$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData_W2$Score_Full.prop
W = 0.95468, p-value = 0.3647
#Normal
##Model as a function of Site and Genotype
Tol_ScoreF_W2_lm<-lm(Score_Full.prop~Site+Genotype+Site:Genotype, data=TolData_W2)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_W2_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_W2_lm)); qqline(resid(Tol_ScoreF_W2_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_W2_lm), resid(Tol_ScoreF_W2_lm))
#Model Results
summary(Tol_ScoreF_W2_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + Site:Genotype,
data = TolData_W2)
Residuals:
Min 1Q Median 3Q Max
-0.278525 -0.066562 -0.002225 0.055925 0.233075
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.59021 0.03151 18.730 8.72e-13 ***
Site.L 0.13062 0.04456 2.931 0.009326 **
Genotype.L -0.27257 0.05529 -4.930 0.000127 ***
Genotype.Q -0.08928 0.05386 -1.658 0.115689
Site.L:Genotype.L 0.00095 0.07820 0.012 0.990448
Site.L:Genotype.Q 0.02195 0.07616 0.288 0.776645
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1503 on 17 degrees of freedom
Multiple R-squared: 0.6882, Adjusted R-squared: 0.5965
F-statistic: 7.505 on 5 and 17 DF, p-value: 0.0006991
anova(Tol_ScoreF_W2_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.24105 0.241048 10.6769 0.0045369 **
Genotype 2 0.60425 0.302123 13.3821 0.0003231 ***
Site:Genotype 2 0.00188 0.000938 0.0415 0.9594056
Residuals 17 0.38380 0.022577
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreF_W2_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 0.20 | [0.00, 1.00]
Genotype | 0.49 | [0.16, 1.00]
Site:Genotype | 1.52e-03 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_W2_lm.res<-data.frame(anova(Tol_ScoreF_W2_lm))
Tol_ScoreF_W2_lm.res$Predictor<-rownames(Tol_ScoreF_W2_lm.res)
Tol_ScoreF_W2_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_W2_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_W2_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_W2_lm.res))
Tol_ScoreF_W2_lm.res$TimeP<-rep("W2", nrow(Tol_ScoreF_W2_lm.res))
Tol_ScoreF_W2_lm.res<-Tol_ScoreF_W2_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreF_W2_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.648 0.0751 17 0.490 0.807
AC12 0.583 0.0751 17 0.425 0.742
AC8 0.262 0.0751 17 0.103 0.420
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.845 0.0751 17 0.686 1.003
AC12 0.743 0.0751 17 0.584 0.901
AC8 0.460 0.0867 17 0.277 0.643
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0649 0.106 17 0.610 0.8165
AC10 - AC8 0.3864 0.106 17 3.637 0.0055
AC12 - AC8 0.3216 0.106 17 3.027 0.0197
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1019 0.106 17 0.959 0.6115
AC10 - AC8 0.3845 0.115 17 3.351 0.0100
AC12 - AC8 0.2826 0.115 17 2.463 0.0610
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreF_W2_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.648 0.0751 17 0.490 0.807
SS 0.845 0.0751 17 0.686 1.003
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.583 0.0751 17 0.425 0.742
SS 0.743 0.0751 17 0.584 0.901
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.262 0.0751 17 0.103 0.420
SS 0.460 0.0867 17 0.277 0.643
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.196 0.106 17 -1.849 0.0819
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.159 0.106 17 -1.500 0.1519
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.198 0.115 17 -1.728 0.1020
##Save p-values
#Genotypes within Sites
Tol_ScoreF_W2_lm.geno<-data.frame(emmeans(Tol_ScoreF_W2_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreF_W2_lm.geno<-Tol_ScoreF_W2_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_W2_lm.geno$group1<-paste(Tol_ScoreF_W2_lm.geno$Site, Tol_ScoreF_W2_lm.geno$group1, sep="_")
Tol_ScoreF_W2_lm.geno$group2<-paste(Tol_ScoreF_W2_lm.geno$Site, Tol_ScoreF_W2_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreF_W2_lm.site<-data.frame(emmeans(Tol_ScoreF_W2_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreF_W2_lm.site<-Tol_ScoreF_W2_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_W2_lm.site$group1<-paste(Tol_ScoreF_W2_lm.site$group1, Tol_ScoreF_W2_lm.site$Genotype, sep="_")
Tol_ScoreF_W2_lm.site$group2<-paste(Tol_ScoreF_W2_lm.site$group2, Tol_ScoreF_W2_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreF_W2_lm.p<-rbind(Tol_ScoreF_W2_lm.geno[,c(1:2,4:8)], Tol_ScoreF_W2_lm.site[,c(1:2,4:8)])
Tol_ScoreF_W2_lm.p<-Tol_ScoreF_W2_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreF_W2_lm.p$Sig<-ifelse(Tol_ScoreF_W2_lm.p$p<0.001, "***", ifelse(Tol_ScoreF_W2_lm.p$p<0.01, "**", ifelse(Tol_ScoreF_W2_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreF_W2_lm.p$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_W2_lm.p))
Tol_ScoreF_W2_lm.p$TimeP<-rep("W2", nrow(Tol_ScoreF_W2_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreF_W2_SG<-summarySE(TolData_W2, measurevar="Score_Full.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreF_W2_SG.plot<-ggplot(Tol_ScoreF_W2_SG, aes(x=Site.Geno, y=Score_Full.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_Full.prop-se, ymax=Score_Full.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention Full Set")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreF_W2_lm.p, y.position=0.8, step.increase=0.2, label="Sig", hide.ns=TRUE); Tol_ScoreF_W2_SG.plot
##Check normality
hist(TolData_M1$Score_Full.prop)
shapiro.test(TolData_M1$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData_M1$Score_Full.prop
W = 0.89303, p-value = 0.02162
#Not normal
##Try square transformation
hist((TolData_M1$Score_Full.prop)^2)
shapiro.test((TolData_M1$Score_Full.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M1$Score_Full.prop)^2
W = 0.89166, p-value = 0.02032
#Not normal
##Try cubed transformation
hist((TolData_M1$Score_Full.prop)^3)
shapiro.test((TolData_M1$Score_Full.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M1$Score_Full.prop)^3
W = 0.87564, p-value = 0.009987
#Not normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_ScoreF_M1_lm<-lm(Score_Full.prop~Site+Genotype+Site:Genotype, data=TolData_M1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_M1_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_M1_lm)); qqline(resid(Tol_ScoreF_M1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_M1_lm), resid(Tol_ScoreF_M1_lm))
#Model Results
summary(Tol_ScoreF_M1_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M1)
Residuals:
Min 1Q Median 3Q Max
-0.273000 -0.037612 0.002175 0.037825 0.271000
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.75883 0.02730 27.794 5.7e-15 ***
Site.L 0.09080 0.03861 2.352 0.031829 *
Genotype.L -0.21843 0.04486 -4.869 0.000171 ***
Genotype.Q 0.12173 0.04960 2.454 0.025939 *
Site.L:Genotype.L 0.10760 0.06344 1.696 0.109255
Site.L:Genotype.Q 0.01756 0.07014 0.250 0.805486
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.1269 on 16 degrees of freedom
Multiple R-squared: 0.7062, Adjusted R-squared: 0.6144
F-statistic: 7.693 on 5 and 16 DF, p-value: 0.0007452
anova(Tol_ScoreF_M1_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.09331 0.093314 5.7958 0.0284942 *
Genotype 2 0.47867 0.239337 14.8652 0.0002246 ***
Site:Genotype 2 0.04732 0.023660 1.4695 0.2594726
Residuals 16 0.25761 0.016100
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreF_M1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.11 | [0.00, 1.00]
Genotype | 0.55 | [0.21, 1.00]
Site:Genotype | 0.05 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_M1_lm.res<-data.frame(anova(Tol_ScoreF_M1_lm))
Tol_ScoreF_M1_lm.res$Predictor<-rownames(Tol_ScoreF_M1_lm.res)
Tol_ScoreF_M1_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_M1_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_M1_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M1_lm.res))
Tol_ScoreF_M1_lm.res$TimeP<-rep("M1", nrow(Tol_ScoreF_M1_lm.res))
Tol_ScoreF_M1_lm.res<-Tol_ScoreF_M1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreF_M1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.948 0.0634 16 0.813 1.082
AC12 0.605 0.0733 16 0.450 0.761
AC8 0.531 0.0634 16 0.397 0.665
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.978 0.0634 16 0.844 1.113
AC12 0.714 0.0733 16 0.558 0.869
AC8 0.777 0.0634 16 0.643 0.912
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.3421 0.0969 16 3.530 0.0074
AC10 - AC8 0.4165 0.0897 16 4.642 0.0007
AC12 - AC8 0.0744 0.0969 16 0.767 0.7277
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.2650 0.0969 16 2.734 0.0371
AC10 - AC8 0.2013 0.0897 16 2.244 0.0939
AC12 - AC8 -0.0636 0.0969 16 -0.657 0.7913
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreF_M1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.948 0.0634 16 0.813 1.082
SS 0.978 0.0634 16 0.844 1.113
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.605 0.0733 16 0.450 0.761
SS 0.714 0.0733 16 0.558 0.869
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.531 0.0634 16 0.397 0.665
SS 0.777 0.0634 16 0.643 0.912
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0309 0.0897 16 -0.345 0.7346
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.1081 0.1036 16 -1.044 0.3121
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.2462 0.0897 16 -2.743 0.0144
##Save p-values
#Genotypes within Sites
Tol_ScoreF_M1_lm.geno<-data.frame(emmeans(Tol_ScoreF_M1_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreF_M1_lm.geno<-Tol_ScoreF_M1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M1_lm.geno$group1<-paste(Tol_ScoreF_M1_lm.geno$Site, Tol_ScoreF_M1_lm.geno$group1, sep="_")
Tol_ScoreF_M1_lm.geno$group2<-paste(Tol_ScoreF_M1_lm.geno$Site, Tol_ScoreF_M1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreF_M1_lm.site<-data.frame(emmeans(Tol_ScoreF_M1_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreF_M1_lm.site<-Tol_ScoreF_M1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M1_lm.site$group1<-paste(Tol_ScoreF_M1_lm.site$group1, Tol_ScoreF_M1_lm.site$Genotype, sep="_")
Tol_ScoreF_M1_lm.site$group2<-paste(Tol_ScoreF_M1_lm.site$group2, Tol_ScoreF_M1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreF_M1_lm.p<-rbind(Tol_ScoreF_M1_lm.geno[,c(1:2,4:8)], Tol_ScoreF_M1_lm.site[,c(1:2,4:8)])
Tol_ScoreF_M1_lm.p<-Tol_ScoreF_M1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreF_M1_lm.p$Sig<-ifelse(Tol_ScoreF_M1_lm.p$p<0.001, "***", ifelse(Tol_ScoreF_M1_lm.p$p<0.01, "**", ifelse(Tol_ScoreF_M1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreF_M1_lm.p$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M1_lm.p))
Tol_ScoreF_M1_lm.p$TimeP<-rep("M1", nrow(Tol_ScoreF_M1_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreF_M1_SG<-summarySE(TolData_M1, measurevar="Score_Full.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreF_M1_SG.plot<-ggplot(Tol_ScoreF_M1_SG, aes(x=Site.Geno, y=Score_Full.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_Full.prop-se, ymax=Score_Full.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention Full Set")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreF_M1_lm.p, y.position=1.1, step.increase=0.2, label="Sig", hide.ns=TRUE); Tol_ScoreF_M1_SG.plot
##Check normality
hist(TolData_M4$Score_Full.prop)
shapiro.test(TolData_M4$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData_M4$Score_Full.prop
W = 0.84977, p-value = 0.002165
#Not Normal
##Try square transformation
hist((TolData_M4$Score_Full.prop)^2)
shapiro.test((TolData_M4$Score_Full.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M4$Score_Full.prop)^2
W = 0.85122, p-value = 0.002303
#Not Normal
##Try cubed transformation
hist((TolData_M4$Score_Full.prop)^3)
shapiro.test((TolData_M4$Score_Full.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M4$Score_Full.prop)^3
W = 0.85118, p-value = 0.002299
#Not Normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_ScoreF_M4_lm<-lm(Score_Full.prop~Site+Genotype+Site:Genotype, data=TolData_M4)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_M4_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_M4_lm)); qqline(resid(Tol_ScoreF_M4_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_M4_lm), resid(Tol_ScoreF_M4_lm))
#Model Results
summary(Tol_ScoreF_M4_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M4)
Residuals:
Min 1Q Median 3Q Max
-0.18507 -0.02627 0.00710 0.02830 0.13483
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.86734 0.01507 57.567 < 2e-16 ***
Site.L 0.04613 0.02131 2.165 0.0441 *
Genotype.L -0.17466 0.02610 -6.693 2.81e-06 ***
Genotype.Q -0.02464 0.02610 -0.944 0.3575
Site.L:Genotype.L 0.02404 0.03691 0.651 0.5231
Site.L:Genotype.Q -0.05278 0.03691 -1.430 0.1698
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.07381 on 18 degrees of freedom
Multiple R-squared: 0.7459, Adjusted R-squared: 0.6754
F-statistic: 10.57 on 5 and 18 DF, p-value: 7.375e-05
anova(Tol_ScoreF_M4_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.025532 0.025532 4.6865 0.04408 *
Genotype 2 0.248919 0.124459 22.8449 1.15e-05 ***
Site:Genotype 2 0.013453 0.006726 1.2347 0.31443
Residuals 18 0.098064 0.005448
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreF_M4_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.07 | [0.00, 1.00]
Genotype | 0.64 | [0.37, 1.00]
Site:Genotype | 0.03 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_M4_lm.res<-data.frame(anova(Tol_ScoreF_M4_lm))
Tol_ScoreF_M4_lm.res$Predictor<-rownames(Tol_ScoreF_M4_lm.res)
Tol_ScoreF_M4_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_M4_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_M4_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M4_lm.res))
Tol_ScoreF_M4_lm.res$TimeP<-rep("M4", nrow(Tol_ScoreF_M4_lm.res))
Tol_ScoreF_M4_lm.res<-Tol_ScoreF_M4_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreF_M4_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.975 0.0369 18 0.898 1.053
AC12 0.824 0.0369 18 0.747 0.902
AC8 0.704 0.0369 18 0.627 0.782
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.986 0.0369 18 0.909 1.064
AC12 0.951 0.0369 18 0.873 1.028
AC8 0.763 0.0369 18 0.686 0.841
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1510 0.0522 18 2.894 0.0249
AC10 - AC8 0.2711 0.0522 18 5.193 0.0002
AC12 - AC8 0.1200 0.0522 18 2.299 0.0816
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0356 0.0522 18 0.682 0.7767
AC10 - AC8 0.2230 0.0522 18 4.272 0.0013
AC12 - AC8 0.1874 0.0522 18 3.590 0.0056
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreF_M4_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.975 0.0369 18 0.898 1.053
SS 0.986 0.0369 18 0.909 1.064
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.824 0.0369 18 0.747 0.902
SS 0.951 0.0369 18 0.873 1.028
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.704 0.0369 18 0.627 0.782
SS 0.763 0.0369 18 0.686 0.841
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0107 0.0522 18 -0.205 0.8395
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.1262 0.0522 18 -2.418 0.0265
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0588 0.0522 18 -1.127 0.2747
##Save p-values
#Genotypes within Sites
Tol_ScoreF_M4_lm.geno<-data.frame(emmeans(Tol_ScoreF_M4_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreF_M4_lm.geno<-Tol_ScoreF_M4_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M4_lm.geno$group1<-paste(Tol_ScoreF_M4_lm.geno$Site, Tol_ScoreF_M4_lm.geno$group1, sep="_")
Tol_ScoreF_M4_lm.geno$group2<-paste(Tol_ScoreF_M4_lm.geno$Site, Tol_ScoreF_M4_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreF_M4_lm.site<-data.frame(emmeans(Tol_ScoreF_M4_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreF_M4_lm.site<-Tol_ScoreF_M4_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M4_lm.site$group1<-paste(Tol_ScoreF_M4_lm.site$group1, Tol_ScoreF_M4_lm.site$Genotype, sep="_")
Tol_ScoreF_M4_lm.site$group2<-paste(Tol_ScoreF_M4_lm.site$group2, Tol_ScoreF_M4_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreF_M4_lm.p<-rbind(Tol_ScoreF_M4_lm.geno[,c(1:2,4:8)], Tol_ScoreF_M4_lm.site[,c(1:2,4:8)])
Tol_ScoreF_M4_lm.p<-Tol_ScoreF_M4_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreF_M4_lm.p$Sig<-ifelse(Tol_ScoreF_M4_lm.p$p<0.001, "***", ifelse(Tol_ScoreF_M4_lm.p$p<0.01, "**", ifelse(Tol_ScoreF_M4_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreF_M4_lm.p$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M4_lm.p))
Tol_ScoreF_M4_lm.p$TimeP<-rep("M4", nrow(Tol_ScoreF_M4_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreF_M4_SG<-summarySE(TolData_M4, measurevar="Score_Full.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreF_M4_SG.plot<-ggplot(Tol_ScoreF_M4_SG, aes(x=Site.Geno, y=Score_Full.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_Full.prop-se, ymax=Score_Full.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention Full Set")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreF_M4_lm.p, y.position=1.1, step.increase=0.22, label="Sig", hide.ns=TRUE); Tol_ScoreF_M4_SG.plot
##Check normality
hist(TolData_M8$Score_Full.prop)
shapiro.test(TolData_M8$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData_M8$Score_Full.prop
W = 0.70466, p-value = 1.161e-05
#Not Normal
##Try square transformation
hist((TolData_M8$Score_Full.prop)^2)
shapiro.test((TolData_M8$Score_Full.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M8$Score_Full.prop)^2
W = 0.70835, p-value = 1.301e-05
#Not Normal
##Try cubed transformation
hist((TolData_M8$Score_Full.prop)^3)
shapiro.test((TolData_M8$Score_Full.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M8$Score_Full.prop)^3
W = 0.71195, p-value = 1.455e-05
#Not Normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_ScoreF_M8_lm<-lm(Score_Full.prop~Site+Genotype+Site:Genotype, data=TolData_M8)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_M8_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_M8_lm)); qqline(resid(Tol_ScoreF_M8_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_M8_lm), resid(Tol_ScoreF_M8_lm))
#Model Results
summary(Tol_ScoreF_M8_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M8)
Residuals:
Min 1Q Median 3Q Max
-0.04225 -0.00625 0.00015 0.00675 0.03333
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.982546 0.003520 279.166 < 2e-16 ***
Site.L 0.017943 0.004977 3.605 0.00203 **
Genotype.L -0.014257 0.006096 -2.339 0.03109 *
Genotype.Q -0.017213 0.006096 -2.824 0.01125 *
Site.L:Genotype.L 0.019513 0.008621 2.263 0.03621 *
Site.L:Genotype.Q 0.016346 0.008621 1.896 0.07412 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.01724 on 18 degrees of freedom
Multiple R-squared: 0.6614, Adjusted R-squared: 0.5673
F-statistic: 7.031 on 5 and 18 DF, p-value: 0.0008379
anova(Tol_ScoreF_M8_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.0038633 0.0038633 12.9949 0.002025 **
Genotype 2 0.0039963 0.0019982 6.7211 0.006604 **
Site:Genotype 2 0.0025917 0.0012959 4.3589 0.028593 *
Residuals 18 0.0053513 0.0002973
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreF_M8_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.24 | [0.02, 1.00]
Genotype | 0.25 | [0.00, 1.00]
Site:Genotype | 0.16 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_M8_lm.res<-data.frame(anova(Tol_ScoreF_M8_lm))
Tol_ScoreF_M8_lm.res$Predictor<-rownames(Tol_ScoreF_M8_lm.res)
Tol_ScoreF_M8_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_M8_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_M8_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M8_lm.res))
Tol_ScoreF_M8_lm.res$TimeP<-rep("M8", nrow(Tol_ScoreF_M8_lm.res))
Tol_ScoreF_M8_lm.res<-Tol_ScoreF_M8_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site, Genotype, and Site * Genotype.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreF_M8_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.978 0.00862 18 0.960 0.996
AC12 0.993 0.00862 18 0.975 1.011
AC8 0.938 0.00862 18 0.920 0.956
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.993 0.00862 18 0.975 1.011
AC12 1.000 0.00862 18 0.982 1.018
AC8 0.993 0.00862 18 0.974 1.011
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.01540 0.0122 18 -1.263 0.4332
AC10 - AC8 0.03968 0.0122 18 3.254 0.0117
AC12 - AC8 0.05507 0.0122 18 4.517 0.0007
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.00660 0.0122 18 -0.541 0.8521
AC10 - AC8 0.00065 0.0122 18 0.053 0.9984
AC12 - AC8 0.00725 0.0122 18 0.595 0.8247
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreF_M8_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.978 0.00862 18 0.960 0.996
SS 0.993 0.00862 18 0.975 1.011
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.993 0.00862 18 0.975 1.011
SS 1.000 0.00862 18 0.982 1.018
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.938 0.00862 18 0.920 0.956
SS 0.993 0.00862 18 0.974 1.011
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0153 0.0122 18 -1.255 0.2256
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0065 0.0122 18 -0.533 0.6005
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0543 0.0122 18 -4.456 0.0003
##Save p-values
#Genotypes within Sites
Tol_ScoreF_M8_lm.geno<-data.frame(emmeans(Tol_ScoreF_M8_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreF_M8_lm.geno<-Tol_ScoreF_M8_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M8_lm.geno$group1<-paste(Tol_ScoreF_M8_lm.geno$Site, Tol_ScoreF_M8_lm.geno$group1, sep="_")
Tol_ScoreF_M8_lm.geno$group2<-paste(Tol_ScoreF_M8_lm.geno$Site, Tol_ScoreF_M8_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreF_M8_lm.site<-data.frame(emmeans(Tol_ScoreF_M8_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreF_M8_lm.site<-Tol_ScoreF_M8_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M8_lm.site$group1<-paste(Tol_ScoreF_M8_lm.site$group1, Tol_ScoreF_M8_lm.site$Genotype, sep="_")
Tol_ScoreF_M8_lm.site$group2<-paste(Tol_ScoreF_M8_lm.site$group2, Tol_ScoreF_M8_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreF_M8_lm.p<-rbind(Tol_ScoreF_M8_lm.geno[,c(1:2,4:8)], Tol_ScoreF_M8_lm.site[,c(1:2,4:8)])
Tol_ScoreF_M8_lm.p<-Tol_ScoreF_M8_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreF_M8_lm.p$Sig<-ifelse(Tol_ScoreF_M8_lm.p$p<0.001, "***", ifelse(Tol_ScoreF_M8_lm.p$p<0.01, "**", ifelse(Tol_ScoreF_M8_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreF_M8_lm.p$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M8_lm.p))
Tol_ScoreF_M8_lm.p$TimeP<-rep("M8", nrow(Tol_ScoreF_M8_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreF_M8_SG<-summarySE(TolData_M8, measurevar="Score_Full.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreF_M8_SG.plot<-ggplot(Tol_ScoreF_M8_SG, aes(x=Site.Geno, y=Score_Full.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_Full.prop-se, ymax=Score_Full.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention Full Set")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreF_M8_lm.p, y.position=1.1, step.increase=0.45, label="Sig", hide.ns=TRUE); Tol_ScoreF_M8_SG.plot
##Check normality
hist(TolData_M12$Score_Full.prop)
shapiro.test(TolData_M12$Score_Full.prop)
Shapiro-Wilk normality test
data: TolData_M12$Score_Full.prop
W = 0.98901, p-value = 0.9934
#Normal
##Model as a function of Site and Genotype
Tol_ScoreF_M12_lm<-lm(Score_Full.prop~Site+Genotype+Site:Genotype, data=TolData_M12)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreF_M12_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreF_M12_lm)); qqline(resid(Tol_ScoreF_M12_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreF_M12_lm), resid(Tol_ScoreF_M12_lm))
#Model Results
summary(Tol_ScoreF_M12_lm)
Call:
lm(formula = Score_Full.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M12)
Residuals:
Min 1Q Median 3Q Max
-0.35442 -0.11678 0.00443 0.10991 0.39832
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.560671 0.043883 12.777 1.83e-10 ***
Site.L 0.004095 0.062059 0.066 0.948
Genotype.L -0.006930 0.076007 -0.091 0.928
Genotype.Q 0.011339 0.076007 0.149 0.883
Site.L:Genotype.L 0.005825 0.107490 0.054 0.957
Site.L:Genotype.Q -0.082041 0.107490 -0.763 0.455
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.215 on 18 degrees of freedom
Multiple R-squared: 0.03332, Adjusted R-squared: -0.2352
F-statistic: 0.1241 on 5 and 18 DF, p-value: 0.9851
anova(Tol_ScoreF_M12_lm)
Analysis of Variance Table
Response: Score_Full.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.00020 0.000201 0.0044 0.9481
Genotype 2 0.00141 0.000706 0.0153 0.9848
Site:Genotype 2 0.02706 0.013529 0.2927 0.7497
Residuals 18 0.83190 0.046216
#Effect Size of Predictors
eta_squared(Tol_ScoreF_M12_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 2.34e-04 | [0.00, 1.00]
Genotype | 1.64e-03 | [0.00, 1.00]
Site:Genotype | 0.03 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreF_M12_lm.res<-data.frame(anova(Tol_ScoreF_M12_lm))
Tol_ScoreF_M12_lm.res$Predictor<-rownames(Tol_ScoreF_M12_lm.res)
Tol_ScoreF_M12_lm.res$EtaSq<-c(eta_squared(Tol_ScoreF_M12_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreF_M12_lm.res$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M12_lm.res))
Tol_ScoreF_M12_lm.res$TimeP<-rep("M12", nrow(Tol_ScoreF_M12_lm.res))
Tol_ScoreF_M12_lm.res<-Tol_ScoreF_M12_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
No significant effects of Site or Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreF_M12_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.594 0.107 18 0.368 0.820
AC12 0.501 0.107 18 0.275 0.727
AC8 0.578 0.107 18 0.352 0.804
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.546 0.107 18 0.321 0.772
AC12 0.602 0.107 18 0.376 0.828
AC8 0.543 0.107 18 0.317 0.768
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.09275 0.152 18 0.610 0.8165
AC10 - AC8 0.01562 0.152 18 0.103 0.9942
AC12 - AC8 -0.07712 0.152 18 -0.507 0.8687
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.05518 0.152 18 -0.363 0.9302
AC10 - AC8 0.00398 0.152 18 0.026 0.9996
AC12 - AC8 0.05915 0.152 18 0.389 0.9203
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreF_M12_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.594 0.107 18 0.368 0.820
SS 0.546 0.107 18 0.321 0.772
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.501 0.107 18 0.275 0.727
SS 0.602 0.107 18 0.376 0.828
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.578 0.107 18 0.352 0.804
SS 0.543 0.107 18 0.317 0.768
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.0474 0.152 18 0.312 0.7588
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.1005 0.152 18 -0.661 0.5168
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.0357 0.152 18 0.235 0.8167
##Save p-values
#Genotypes within Sites
Tol_ScoreF_M12_lm.geno<-data.frame(emmeans(Tol_ScoreF_M12_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreF_M12_lm.geno<-Tol_ScoreF_M12_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M12_lm.geno$group1<-paste(Tol_ScoreF_M12_lm.geno$Site, Tol_ScoreF_M12_lm.geno$group1, sep="_")
Tol_ScoreF_M12_lm.geno$group2<-paste(Tol_ScoreF_M12_lm.geno$Site, Tol_ScoreF_M12_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreF_M12_lm.site<-data.frame(emmeans(Tol_ScoreF_M12_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreF_M12_lm.site<-Tol_ScoreF_M12_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreF_M12_lm.site$group1<-paste(Tol_ScoreF_M12_lm.site$group1, Tol_ScoreF_M12_lm.site$Genotype, sep="_")
Tol_ScoreF_M12_lm.site$group2<-paste(Tol_ScoreF_M12_lm.site$group2, Tol_ScoreF_M12_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreF_M12_lm.p<-rbind(Tol_ScoreF_M12_lm.geno[,c(1:2,4:8)], Tol_ScoreF_M12_lm.site[,c(1:2,4:8)])
Tol_ScoreF_M12_lm.p<-Tol_ScoreF_M12_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreF_M12_lm.p$Sig<-ifelse(Tol_ScoreF_M12_lm.p$p<0.001, "***", ifelse(Tol_ScoreF_M12_lm.p$p<0.01, "**", ifelse(Tol_ScoreF_M12_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreF_M12_lm.p$Response<-rep("Color_FullSet", nrow(Tol_ScoreF_M12_lm.p))
Tol_ScoreF_M12_lm.p$TimeP<-rep("M12", nrow(Tol_ScoreF_M12_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreF_M12_SG<-summarySE(TolData_M12, measurevar="Score_Full.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreF_M12_SG.plot<-ggplot(Tol_ScoreF_M12_SG, aes(x=Site.Geno, y=Score_Full.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_Full.prop-se, ymax=Score_Full.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention Full Set")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o); Tol_ScoreF_M12_SG.plot
#+ stat_pvalue_manual(data=Tol_ScoreF_M12_lm.p, y.position=0.8, step.increase=0.15, label="Sig", hide.ns=TRUE) #No significant differences
##Check normality
hist(TolData$Score_TP.prop)
shapiro.test(TolData$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData$Score_TP.prop
W = 0.90982, p-value = 1.131e-07
#Not Normal
##Try square transformation
hist((TolData$Score_TP.prop)^2)
shapiro.test((TolData$Score_TP.prop)^2)
Shapiro-Wilk normality test
data: (TolData$Score_TP.prop)^2
W = 0.91267, p-value = 1.662e-07
#Not normal
##Try cubed transformation
hist((TolData$Score_TP.prop)^3)
shapiro.test((TolData$Score_TP.prop)^3)
Shapiro-Wilk normality test
data: (TolData$Score_TP.prop)^3
W = 0.91228, p-value = 1.576e-07
#Not normal
##Model as a function of Site and Genotype and Timepoint
##Model with no transformation and check residuals
Tol_ScoreTP_lm<-lm(Score_TP.prop~Site+Genotype+TimeP+ Site:Genotype + Site:TimeP + Genotype:TimeP, data=TolData)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_lm)); qqline(resid(Tol_ScoreTP_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_lm), resid(Tol_ScoreTP_lm))
Residuals are not great, need to check for other modeling options for Color by Timepoint.
#Model Results
summary(Tol_ScoreTP_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + TimeP + Site:Genotype +
Site:TimeP + Genotype:TimeP, data = TolData)
Residuals:
Min 1Q Median 3Q Max
-0.131312 -0.020263 0.000578 0.024756 0.197254
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.881350 0.004721 186.703 < 2e-16 ***
Site.L 0.022025 0.006667 3.303 0.00128 **
Genotype.L -0.069663 0.008087 -8.615 4.55e-14 ***
Genotype.Q -0.003731 0.008267 -0.451 0.65264
TimeP.L 0.025048 0.011511 2.176 0.03163 *
TimeP.Q -0.087603 0.011572 -7.570 1.05e-11 ***
TimeP.C -0.118674 0.011539 -10.285 < 2e-16 ***
TimeP^4 -0.042897 0.011556 -3.712 0.00032 ***
TimeP^5 -0.001804 0.011641 -0.155 0.87709
Site.L:Genotype.L 0.012920 0.011436 1.130 0.26096
Site.L:Genotype.Q -0.005427 0.011667 -0.465 0.64272
Site.L:TimeP.L -0.042723 0.016279 -2.624 0.00987 **
Site.L:TimeP.Q -0.021374 0.016333 -1.309 0.19329
Site.L:TimeP.C 0.031161 0.016301 1.912 0.05844 .
Site.L:TimeP^4 -0.013056 0.016328 -0.800 0.42562
Site.L:TimeP^5 -0.002359 0.016413 -0.144 0.88595
Genotype.L:TimeP.L 0.111835 0.019779 5.654 1.18e-07 ***
Genotype.Q:TimeP.L 0.025829 0.020102 1.285 0.20143
Genotype.L:TimeP.Q 0.033332 0.019692 1.693 0.09325 .
Genotype.Q:TimeP.Q -0.032889 0.020388 -1.613 0.10947
Genotype.L:TimeP.C -0.033689 0.019887 -1.694 0.09299 .
Genotype.Q:TimeP.C 0.020276 0.020079 1.010 0.31472
Genotype.L:TimeP^4 -0.028548 0.019923 -1.433 0.15463
Genotype.Q:TimeP^4 0.047390 0.020106 2.357 0.02013 *
Genotype.L:TimeP^5 -0.005818 0.019758 -0.294 0.76894
Genotype.Q:TimeP^5 -0.052202 0.020560 -2.539 0.01246 *
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.05567 on 114 degrees of freedom
Multiple R-squared: 0.7496, Adjusted R-squared: 0.6947
F-statistic: 13.65 on 25 and 114 DF, p-value: < 2.2e-16
anova(Tol_ScoreTP_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.03614 0.036137 11.6592 0.0008856 ***
Genotype 2 0.22657 0.113283 36.5499 5.438e-13 ***
TimeP 5 0.57600 0.115200 37.1681 < 2.2e-16 ***
Site:Genotype 2 0.00459 0.002295 0.7403 0.4792450
Site:TimeP 5 0.04293 0.008587 2.7704 0.0212094 *
Genotype:TimeP 10 0.17174 0.017174 5.5410 1.081e-06 ***
Residuals 114 0.35333 0.003099
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
----------------------------------------
Site | 0.03 | [0.00, 1.00]
Genotype | 0.16 | [0.06, 1.00]
TimeP | 0.41 | [0.28, 1.00]
Site:Genotype | 3.25e-03 | [0.00, 1.00]
Site:TimeP | 0.03 | [0.00, 1.00]
Genotype:TimeP | 0.12 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_lm.res<-data.frame(anova(Tol_ScoreTP_lm))
Tol_ScoreTP_lm.res$Predictor<-rownames(Tol_ScoreTP_lm.res)
Tol_ScoreTP_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_lm.res))
Tol_ScoreTP_lm.res<-Tol_ScoreTP_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Strong influence of Timepoint, including interactions with variables of interest, Site and Genotype. Will analyze each Timepoint individually.
##Check normality
hist(TolData_W1$Score_TP.prop)
shapiro.test(TolData_W1$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData_W1$Score_TP.prop
W = 0.95164, p-value = 0.3163
#Normal
##Model as a function of Site and Genotype
Tol_ScoreTP_W1_lm<-lm(Score_TP.prop~Site+Genotype+Site:Genotype, data=TolData_W1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_W1_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_W1_lm)); qqline(resid(Tol_ScoreTP_W1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_W1_lm), resid(Tol_ScoreTP_W1_lm))
#Model Results
summary(Tol_ScoreTP_W1_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + Site:Genotype,
data = TolData_W1)
Residuals:
Min 1Q Median 3Q Max
-0.08550 -0.03194 0.00125 0.02194 0.12747
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.85368 0.01204 70.904 < 2e-16 ***
Site.L 0.02035 0.01703 1.195 0.248
Genotype.L -0.11079 0.02030 -5.458 4.25e-05 ***
Genotype.Q -0.02962 0.02140 -1.384 0.184
Site.L:Genotype.L 0.00375 0.02871 0.131 0.898
Site.L:Genotype.Q 0.03416 0.03026 1.129 0.275
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.05741 on 17 degrees of freedom
Multiple R-squared: 0.6715, Adjusted R-squared: 0.5749
F-statistic: 6.95 on 5 and 17 DF, p-value: 0.001056
anova(Tol_ScoreTP_W1_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.004620 0.004620 1.4017 0.2527326
Genotype 2 0.105653 0.052826 16.0279 0.0001224 ***
Site:Genotype 2 0.004257 0.002129 0.6458 0.5366252
Residuals 17 0.056030 0.003296
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_W1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.03 | [0.00, 1.00]
Genotype | 0.62 | [0.32, 1.00]
Site:Genotype | 0.02 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_W1_lm.res<-data.frame(anova(Tol_ScoreTP_W1_lm))
Tol_ScoreTP_W1_lm.res$Predictor<-rownames(Tol_ScoreTP_W1_lm.res)
Tol_ScoreTP_W1_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_W1_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_W1_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_W1_lm.res))
Tol_ScoreTP_W1_lm.res$TimeP<-rep("W1", nrow(Tol_ScoreTP_W1_lm.res))
Tol_ScoreTP_W1_lm.res<-Tol_ScoreTP_W1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreTP_W1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.898 0.0287 17 0.837 0.958
AC12 0.883 0.0287 17 0.823 0.944
AC8 0.737 0.0287 17 0.677 0.798
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.942 0.0287 17 0.882 1.003
AC12 0.873 0.0331 17 0.803 0.942
AC8 0.789 0.0287 17 0.729 0.850
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0143 0.0406 17 0.353 0.9337
AC10 - AC8 0.1604 0.0406 17 3.952 0.0028
AC12 - AC8 0.1461 0.0406 17 3.598 0.0060
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0698 0.0438 17 1.591 0.2763
AC10 - AC8 0.1529 0.0406 17 3.767 0.0042
AC12 - AC8 0.0832 0.0438 17 1.897 0.1700
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreTP_W1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.898 0.0287 17 0.837 0.958
SS 0.942 0.0287 17 0.882 1.003
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.883 0.0287 17 0.823 0.944
SS 0.873 0.0331 17 0.803 0.942
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.737 0.0287 17 0.677 0.798
SS 0.789 0.0287 17 0.729 0.850
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0447 0.0406 17 -1.102 0.2857
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS 0.0107 0.0438 17 0.243 0.8107
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0522 0.0406 17 -1.287 0.2153
##Save p-values
#Genotypes within Sites
Tol_ScoreTP_W1_lm.geno<-data.frame(emmeans(Tol_ScoreTP_W1_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreTP_W1_lm.geno<-Tol_ScoreTP_W1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_W1_lm.geno$group1<-paste(Tol_ScoreTP_W1_lm.geno$Site, Tol_ScoreTP_W1_lm.geno$group1, sep="_")
Tol_ScoreTP_W1_lm.geno$group2<-paste(Tol_ScoreTP_W1_lm.geno$Site, Tol_ScoreTP_W1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreTP_W1_lm.site<-data.frame(emmeans(Tol_ScoreTP_W1_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreTP_W1_lm.site<-Tol_ScoreTP_W1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_W1_lm.site$group1<-paste(Tol_ScoreTP_W1_lm.site$group1, Tol_ScoreTP_W1_lm.site$Genotype, sep="_")
Tol_ScoreTP_W1_lm.site$group2<-paste(Tol_ScoreTP_W1_lm.site$group2, Tol_ScoreTP_W1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreTP_W1_lm.p<-rbind(Tol_ScoreTP_W1_lm.geno[,c(1:2,4:8)], Tol_ScoreTP_W1_lm.site[,c(1:2,4:8)])
Tol_ScoreTP_W1_lm.p<-Tol_ScoreTP_W1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreTP_W1_lm.p$Sig<-ifelse(Tol_ScoreTP_W1_lm.p$p<0.001, "***", ifelse(Tol_ScoreTP_W1_lm.p$p<0.01, "**", ifelse(Tol_ScoreTP_W1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreTP_W1_lm.p$Response<-rep("Color_TP", nrow(Tol_ScoreTP_W1_lm.p))
Tol_ScoreTP_W1_lm.p$TimeP<-rep("W1", nrow(Tol_ScoreTP_W1_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreTP_W1_SG<-summarySE(TolData_W1, measurevar="Score_TP.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreTP_W1_SG.plot<-ggplot(Tol_ScoreTP_W1_SG, aes(x=Site.Geno, y=Score_TP.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_TP.prop-se, ymax=Score_TP.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention by Timepoint")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreTP_W1_lm.p, y.position=1, step.increase=0.45, label="Sig", hide.ns=TRUE); Tol_ScoreTP_W1_SG.plot
##Check normality
hist(TolData_W2$Score_TP.prop)
shapiro.test(TolData_W2$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData_W2$Score_TP.prop
W = 0.95832, p-value = 0.4302
#Normal
##Model as a function of Site and Genotype
Tol_ScoreTP_W2_lm<-lm(Score_TP.prop~Site+Genotype+Site:Genotype, data=TolData_W2)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_W2_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_W2_lm)); qqline(resid(Tol_ScoreTP_W2_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_W2_lm), resid(Tol_ScoreTP_W2_lm))
#Model Results
summary(Tol_ScoreTP_W2_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + Site:Genotype,
data = TolData_W2)
Residuals:
Min 1Q Median 3Q Max
-0.117075 -0.028442 -0.002075 0.023658 0.099425
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.843522 0.013080 64.488 < 2e-16 ***
Site.L 0.062257 0.018498 3.366 0.00367 **
Genotype.L -0.117129 0.022952 -5.103 8.83e-05 ***
Genotype.Q -0.042426 0.022356 -1.898 0.07485 .
Site.L:Genotype.L -0.002071 0.032459 -0.064 0.94987
Site.L:Genotype.Q 0.004044 0.031616 0.128 0.89972
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.06237 on 17 degrees of freedom
Multiple R-squared: 0.7169, Adjusted R-squared: 0.6336
F-statistic: 8.61 on 5 and 17 DF, p-value: 0.0003242
anova(Tol_ScoreTP_W2_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.054151 0.054151 13.9200 0.0016623 **
Genotype 2 0.113242 0.056621 14.5549 0.0002073 ***
Site:Genotype 2 0.000083 0.000041 0.0106 0.9894534
Residuals 17 0.066133 0.003890
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_W2_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 0.23 | [0.01, 1.00]
Genotype | 0.48 | [0.15, 1.00]
Site:Genotype | 3.53e-04 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_W2_lm.res<-data.frame(anova(Tol_ScoreTP_W2_lm))
Tol_ScoreTP_W2_lm.res$Predictor<-rownames(Tol_ScoreTP_W2_lm.res)
Tol_ScoreTP_W2_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_W2_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_W2_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_W2_lm.res))
Tol_ScoreTP_W2_lm.res$TimeP<-rep("W2", nrow(Tol_ScoreTP_W2_lm.res))
Tol_ScoreTP_W2_lm.res<-Tol_ScoreTP_W2_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreTP_W2_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.863 0.0312 17 0.797 0.929
AC12 0.836 0.0312 17 0.771 0.902
AC8 0.699 0.0312 17 0.633 0.765
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.955 0.0312 17 0.889 1.021
AC12 0.920 0.0312 17 0.854 0.986
AC8 0.788 0.0360 17 0.712 0.864
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0263 0.0441 17 0.597 0.8236
AC10 - AC8 0.1636 0.0441 17 3.709 0.0047
AC12 - AC8 0.1373 0.0441 17 3.112 0.0166
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0354 0.0441 17 0.803 0.7065
AC10 - AC8 0.1677 0.0476 17 3.521 0.0070
AC12 - AC8 0.1323 0.0476 17 2.778 0.0328
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreTP_W2_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.863 0.0312 17 0.797 0.929
SS 0.955 0.0312 17 0.889 1.021
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.836 0.0312 17 0.771 0.902
SS 0.920 0.0312 17 0.854 0.986
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.699 0.0312 17 0.633 0.765
SS 0.788 0.0360 17 0.712 0.864
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0925 0.0441 17 -2.096 0.0513
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0834 0.0441 17 -1.890 0.0759
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0883 0.0476 17 -1.854 0.0812
##Save p-values
#Genotypes within Sites
Tol_ScoreTP_W2_lm.geno<-data.frame(emmeans(Tol_ScoreTP_W2_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreTP_W2_lm.geno<-Tol_ScoreTP_W2_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_W2_lm.geno$group1<-paste(Tol_ScoreTP_W2_lm.geno$Site, Tol_ScoreTP_W2_lm.geno$group1, sep="_")
Tol_ScoreTP_W2_lm.geno$group2<-paste(Tol_ScoreTP_W2_lm.geno$Site, Tol_ScoreTP_W2_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreTP_W2_lm.site<-data.frame(emmeans(Tol_ScoreTP_W2_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreTP_W2_lm.site<-Tol_ScoreTP_W2_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_W2_lm.site$group1<-paste(Tol_ScoreTP_W2_lm.site$group1, Tol_ScoreTP_W2_lm.site$Genotype, sep="_")
Tol_ScoreTP_W2_lm.site$group2<-paste(Tol_ScoreTP_W2_lm.site$group2, Tol_ScoreTP_W2_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreTP_W2_lm.p<-rbind(Tol_ScoreTP_W2_lm.geno[,c(1:2,4:8)], Tol_ScoreTP_W2_lm.site[,c(1:2,4:8)])
Tol_ScoreTP_W2_lm.p<-Tol_ScoreTP_W2_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreTP_W2_lm.p$Sig<-ifelse(Tol_ScoreTP_W2_lm.p$p<0.001, "***", ifelse(Tol_ScoreTP_W2_lm.p$p<0.01, "**", ifelse(Tol_ScoreTP_W2_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreTP_W2_lm.p$Response<-rep("Color_TP", nrow(Tol_ScoreTP_W2_lm.p))
Tol_ScoreTP_W2_lm.p$TimeP<-rep("W2", nrow(Tol_ScoreTP_W2_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreTP_W2_SG<-summarySE(TolData_W2, measurevar="Score_TP.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreTP_W2_SG.plot<-ggplot(Tol_ScoreTP_W2_SG, aes(x=Site.Geno, y=Score_TP.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_TP.prop-se, ymax=Score_TP.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention by Timepoint")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreTP_W2_lm.p, y.position=1, step.increase=0.45, label="Sig", hide.ns=TRUE); Tol_ScoreTP_W2_SG.plot
##Check normality
hist(TolData_M1$Score_TP.prop)
shapiro.test(TolData_M1$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData_M1$Score_TP.prop
W = 0.9028, p-value = 0.03383
#Not normal
##Try square transformation
hist((TolData_M1$Score_TP.prop)^2)
shapiro.test((TolData_M1$Score_TP.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M1$Score_TP.prop)^2
W = 0.90185, p-value = 0.03238
#Not normal
##Try cubed transformation
hist((TolData_M1$Score_TP.prop)^3)
shapiro.test((TolData_M1$Score_TP.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M1$Score_TP.prop)^3
W = 0.89818, p-value = 0.02735
#Not normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_ScoreTP_M1_lm<-lm(Score_TP.prop~Site+Genotype+Site:Genotype, data=TolData_M1)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_M1_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_M1_lm)); qqline(resid(Tol_ScoreTP_M1_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_M1_lm), resid(Tol_ScoreTP_M1_lm))
#Model Results
summary(Tol_ScoreTP_M1_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M1)
Residuals:
Min 1Q Median 3Q Max
-0.125200 -0.020725 -0.001675 0.015662 0.131000
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.866131 0.012681 68.303 < 2e-16 ***
Site.L 0.041582 0.017933 2.319 0.034 *
Genotype.L -0.114746 0.020837 -5.507 4.78e-05 ***
Genotype.Q 0.064377 0.023036 2.795 0.013 *
Site.L:Genotype.L 0.050375 0.029467 1.710 0.107
Site.L:Genotype.Q 0.004277 0.032577 0.131 0.897
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.05893 on 16 degrees of freedom
Multiple R-squared: 0.7446, Adjusted R-squared: 0.6647
F-statistic: 9.327 on 5 and 16 DF, p-value: 0.0002606
anova(Tol_ScoreTP_M1_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.019311 0.019311 5.5598 0.03144 *
Genotype 2 0.132460 0.066230 19.0683 5.822e-05 ***
Site:Genotype 2 0.010210 0.005105 1.4698 0.25940
Residuals 16 0.055573 0.003473
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_M1_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.09 | [0.00, 1.00]
Genotype | 0.61 | [0.30, 1.00]
Site:Genotype | 0.05 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_M1_lm.res<-data.frame(anova(Tol_ScoreTP_M1_lm))
Tol_ScoreTP_M1_lm.res$Predictor<-rownames(Tol_ScoreTP_M1_lm.res)
Tol_ScoreTP_M1_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_M1_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_M1_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M1_lm.res))
Tol_ScoreTP_M1_lm.res$TimeP<-rep("M1", nrow(Tol_ScoreTP_M1_lm.res))
Tol_ScoreTP_M1_lm.res<-Tol_ScoreTP_M1_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Site and Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreTP_M1_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.968 0.0295 16 0.906 1.031
AC12 0.787 0.0340 16 0.715 0.859
AC8 0.755 0.0295 16 0.693 0.818
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.979 0.0295 16 0.917 1.041
AC12 0.841 0.0340 16 0.768 0.913
AC8 0.867 0.0295 16 0.805 0.930
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1815 0.0450 16 4.032 0.0026
AC10 - AC8 0.2127 0.0417 16 5.103 0.0003
AC12 - AC8 0.0312 0.0450 16 0.693 0.7710
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.1385 0.0450 16 3.077 0.0187
AC10 - AC8 0.1119 0.0417 16 2.685 0.0408
AC12 - AC8 -0.0266 0.0450 16 -0.591 0.8269
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreTP_M1_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.968 0.0295 16 0.906 1.031
SS 0.979 0.0295 16 0.917 1.041
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.787 0.0340 16 0.715 0.859
SS 0.841 0.0340 16 0.768 0.913
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.755 0.0295 16 0.693 0.818
SS 0.867 0.0295 16 0.805 0.930
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.0109 0.0417 16 -0.262 0.7970
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0539 0.0481 16 -1.119 0.2795
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.1116 0.0417 16 -2.679 0.0165
##Save p-values
#Genotypes within Sites
Tol_ScoreTP_M1_lm.geno<-data.frame(emmeans(Tol_ScoreTP_M1_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreTP_M1_lm.geno<-Tol_ScoreTP_M1_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M1_lm.geno$group1<-paste(Tol_ScoreTP_M1_lm.geno$Site, Tol_ScoreTP_M1_lm.geno$group1, sep="_")
Tol_ScoreTP_M1_lm.geno$group2<-paste(Tol_ScoreTP_M1_lm.geno$Site, Tol_ScoreTP_M1_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreTP_M1_lm.site<-data.frame(emmeans(Tol_ScoreTP_M1_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreTP_M1_lm.site<-Tol_ScoreTP_M1_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M1_lm.site$group1<-paste(Tol_ScoreTP_M1_lm.site$group1, Tol_ScoreTP_M1_lm.site$Genotype, sep="_")
Tol_ScoreTP_M1_lm.site$group2<-paste(Tol_ScoreTP_M1_lm.site$group2, Tol_ScoreTP_M1_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreTP_M1_lm.p<-rbind(Tol_ScoreTP_M1_lm.geno[,c(1:2,4:8)], Tol_ScoreTP_M1_lm.site[,c(1:2,4:8)])
Tol_ScoreTP_M1_lm.p<-Tol_ScoreTP_M1_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreTP_M1_lm.p$Sig<-ifelse(Tol_ScoreTP_M1_lm.p$p<0.001, "***", ifelse(Tol_ScoreTP_M1_lm.p$p<0.01, "**", ifelse(Tol_ScoreTP_M1_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreTP_M1_lm.p$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M1_lm.p))
Tol_ScoreTP_M1_lm.p$TimeP<-rep("M1", nrow(Tol_ScoreTP_M1_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreTP_M1_SG<-summarySE(TolData_M1, measurevar="Score_TP.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreTP_M1_SG.plot<-ggplot(Tol_ScoreTP_M1_SG, aes(x=Site.Geno, y=Score_TP.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_TP.prop-se, ymax=Score_TP.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention by Timepoint")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreTP_M1_lm.p, y.position=1.05, step.increase=0.3, label="Sig", hide.ns=TRUE); Tol_ScoreTP_M1_SG.plot
##Check normality
hist(TolData_M4$Score_TP.prop)
shapiro.test(TolData_M4$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData_M4$Score_TP.prop
W = 0.85397, p-value = 0.002593
#Not Normal
##Try square transformation
hist((TolData_M4$Score_TP.prop)^2)
shapiro.test((TolData_M4$Score_TP.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M4$Score_TP.prop)^2
W = 0.85439, p-value = 0.00264
#Not Normal
##Try cubed transformation
hist((TolData_M4$Score_TP.prop)^3)
shapiro.test((TolData_M4$Score_TP.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M4$Score_TP.prop)^3
W = 0.85457, p-value = 0.002661
#Not Normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_ScoreTP_M4_lm<-lm(Score_TP.prop~Site+Genotype+Site:Genotype, data=TolData_M4)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_M4_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_M4_lm)); qqline(resid(Tol_ScoreTP_M4_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_M4_lm), resid(Tol_ScoreTP_M4_lm))
#Model Results
summary(Tol_ScoreTP_M4_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M4)
Residuals:
Min 1Q Median 3Q Max
-0.070400 -0.009438 0.004100 0.011281 0.057100
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.940608 0.006243 150.654 < 2e-16 ***
Site.L 0.010536 0.008830 1.193 0.2483
Genotype.L -0.075254 0.010814 -6.959 1.68e-06 ***
Genotype.Q -0.007308 0.010814 -0.676 0.5078
Site.L:Genotype.L -0.006950 0.015293 -0.454 0.6549
Site.L:Genotype.Q -0.032086 0.015293 -2.098 0.0503 .
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.03059 on 18 degrees of freedom
Multiple R-squared: 0.7531, Adjusted R-squared: 0.6846
F-statistic: 10.98 on 5 and 18 DF, p-value: 5.763e-05
anova(Tol_ScoreTP_M4_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.001332 0.0013321 1.4238 0.2483
Genotype 2 0.045732 0.0228662 24.4414 7.407e-06 ***
Site:Genotype 2 0.004311 0.0021557 2.3042 0.1285
Residuals 18 0.016840 0.0009355
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_M4_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
-----------------------------------
Site | 0.02 | [0.00, 1.00]
Genotype | 0.67 | [0.41, 1.00]
Site:Genotype | 0.06 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_M4_lm.res<-data.frame(anova(Tol_ScoreTP_M4_lm))
Tol_ScoreTP_M4_lm.res$Predictor<-rownames(Tol_ScoreTP_M4_lm.res)
Tol_ScoreTP_M4_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_M4_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_M4_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M4_lm.res))
Tol_ScoreTP_M4_lm.res$TimeP<-rep("M4", nrow(Tol_ScoreTP_M4_lm.res))
Tol_ScoreTP_M4_lm.res<-Tol_ScoreTP_M4_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
Significant effect of Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreTP_M4_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.989 0.0153 18 0.957 1.021
AC12 0.921 0.0153 18 0.888 0.953
AC8 0.890 0.0153 18 0.858 0.922
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.993 0.0153 18 0.960 1.025
AC12 0.973 0.0153 18 0.940 1.005
AC8 0.879 0.0153 18 0.847 0.911
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0686 0.0216 18 3.171 0.0139
AC10 - AC8 0.0995 0.0216 18 4.599 0.0006
AC12 - AC8 0.0309 0.0216 18 1.429 0.3478
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0199 0.0216 18 0.922 0.6335
AC10 - AC8 0.1134 0.0216 18 5.242 0.0002
AC12 - AC8 0.0934 0.0216 18 4.320 0.0011
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreTP_M4_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.989 0.0153 18 0.957 1.021
SS 0.993 0.0153 18 0.960 1.025
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.921 0.0153 18 0.888 0.953
SS 0.973 0.0153 18 0.940 1.005
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.890 0.0153 18 0.858 0.922
SS 0.879 0.0153 18 0.847 0.911
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS -0.00332 0.0216 18 -0.154 0.8795
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.05195 0.0216 18 -2.402 0.0273
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.01057 0.0216 18 0.489 0.6308
##Save p-values
#Genotypes within Sites
Tol_ScoreTP_M4_lm.geno<-data.frame(emmeans(Tol_ScoreTP_M4_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreTP_M4_lm.geno<-Tol_ScoreTP_M4_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M4_lm.geno$group1<-paste(Tol_ScoreTP_M4_lm.geno$Site, Tol_ScoreTP_M4_lm.geno$group1, sep="_")
Tol_ScoreTP_M4_lm.geno$group2<-paste(Tol_ScoreTP_M4_lm.geno$Site, Tol_ScoreTP_M4_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreTP_M4_lm.site<-data.frame(emmeans(Tol_ScoreTP_M4_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreTP_M4_lm.site<-Tol_ScoreTP_M4_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M4_lm.site$group1<-paste(Tol_ScoreTP_M4_lm.site$group1, Tol_ScoreTP_M4_lm.site$Genotype, sep="_")
Tol_ScoreTP_M4_lm.site$group2<-paste(Tol_ScoreTP_M4_lm.site$group2, Tol_ScoreTP_M4_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreTP_M4_lm.p<-rbind(Tol_ScoreTP_M4_lm.geno[,c(1:2,4:8)], Tol_ScoreTP_M4_lm.site[,c(1:2,4:8)])
Tol_ScoreTP_M4_lm.p<-Tol_ScoreTP_M4_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreTP_M4_lm.p$Sig<-ifelse(Tol_ScoreTP_M4_lm.p$p<0.001, "***", ifelse(Tol_ScoreTP_M4_lm.p$p<0.01, "**", ifelse(Tol_ScoreTP_M4_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreTP_M4_lm.p$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M4_lm.p))
Tol_ScoreTP_M4_lm.p$TimeP<-rep("M4", nrow(Tol_ScoreTP_M4_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreTP_M4_SG<-summarySE(TolData_M4, measurevar="Score_TP.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreTP_M4_SG.plot<-ggplot(Tol_ScoreTP_M4_SG, aes(x=Site.Geno, y=Score_TP.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_TP.prop-se, ymax=Score_TP.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention by Timepoint")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o)+
stat_pvalue_manual(data=Tol_ScoreTP_M4_lm.p, y.position=1.1, step.increase=0.4, label="Sig", hide.ns=TRUE); Tol_ScoreTP_M4_SG.plot
##Check normality
hist(TolData_M8$Score_TP.prop)
shapiro.test(TolData_M8$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData_M8$Score_TP.prop
W = 0.76126, p-value = 7.305e-05
#Not Normal
##Try square transformation
hist((TolData_M8$Score_TP.prop)^2)
shapiro.test((TolData_M8$Score_TP.prop)^2)
Shapiro-Wilk normality test
data: (TolData_M8$Score_TP.prop)^2
W = 0.76269, p-value = 7.676e-05
#Not Normal
##Try cubed transformation
hist((TolData_M8$Score_TP.prop)^3)
shapiro.test((TolData_M8$Score_TP.prop)^3)
Shapiro-Wilk normality test
data: (TolData_M8$Score_TP.prop)^3
W = 0.764, p-value = 8.031e-05
#Not Normal
##Model as a function of Site and Genotype
##Model with no transformation and check residuals
Tol_ScoreTP_M8_lm<-lm(Score_TP.prop~Site+Genotype+Site:Genotype, data=TolData_M8)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_M8_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_M8_lm)); qqline(resid(Tol_ScoreTP_M8_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_M8_lm), resid(Tol_ScoreTP_M8_lm))
#Model Results
summary(Tol_ScoreTP_M8_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M8)
Residuals:
Min 1Q Median 3Q Max
-0.033825 -0.003287 0.003600 0.007875 0.028675
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.9866958 0.0034800 283.534 <2e-16 ***
Site.L 0.0009251 0.0049214 0.188 0.8530
Genotype.L 0.0023953 0.0060275 0.397 0.6957
Genotype.Q -0.0118851 0.0060275 -1.972 0.0642 .
Site.L:Genotype.L 0.0174125 0.0085242 2.043 0.0560 .
Site.L:Genotype.Q -0.0026775 0.0085242 -0.314 0.7571
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.01705 on 18 degrees of freedom
Multiple R-squared: 0.317, Adjusted R-squared: 0.1272
F-statistic: 1.671 on 5 and 18 DF, p-value: 0.1927
anova(Tol_ScoreTP_M8_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.0000103 0.00001027 0.0353 0.8530
Genotype 2 0.0011760 0.00058798 2.0230 0.1612
Site:Genotype 2 0.0012415 0.00062073 2.1357 0.1471
Residuals 18 0.0052317 0.00029065
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_M8_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 1.34e-03 | [0.00, 1.00]
Genotype | 0.15 | [0.00, 1.00]
Site:Genotype | 0.16 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_M8_lm.res<-data.frame(anova(Tol_ScoreTP_M8_lm))
Tol_ScoreTP_M8_lm.res$Predictor<-rownames(Tol_ScoreTP_M8_lm.res)
Tol_ScoreTP_M8_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_M8_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_M8_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M8_lm.res))
Tol_ScoreTP_M8_lm.res$TimeP<-rep("M8", nrow(Tol_ScoreTP_M8_lm.res))
Tol_ScoreTP_M8_lm.res<-Tol_ScoreTP_M8_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
No significant effects of Site or Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreTP_M8_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.989 0.00852 18 0.971 1.007
AC12 0.994 0.00852 18 0.976 1.012
AC8 0.975 0.00852 18 0.957 0.993
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.971 0.00852 18 0.953 0.989
AC12 0.999 0.00852 18 0.981 1.017
AC8 0.992 0.00852 18 0.974 1.010
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.00522 0.0121 18 -0.433 0.9022
AC10 - AC8 0.01402 0.0121 18 1.163 0.4892
AC12 - AC8 0.01925 0.0121 18 1.597 0.2725
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.02728 0.0121 18 -2.263 0.0875
AC10 - AC8 -0.02080 0.0121 18 -1.725 0.2232
AC12 - AC8 0.00647 0.0121 18 0.537 0.8542
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreTP_M8_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.989 0.00852 18 0.971 1.007
SS 0.971 0.00852 18 0.953 0.989
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.994 0.00852 18 0.976 1.012
SS 0.999 0.00852 18 0.981 1.017
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.975 0.00852 18 0.957 0.993
SS 0.992 0.00852 18 0.974 1.010
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.0176 0.0121 18 1.464 0.1604
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0044 0.0121 18 -0.365 0.7194
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS -0.0172 0.0121 18 -1.425 0.1713
##Save p-values
#Genotypes within Sites
Tol_ScoreTP_M8_lm.geno<-data.frame(emmeans(Tol_ScoreTP_M8_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreTP_M8_lm.geno<-Tol_ScoreTP_M8_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M8_lm.geno$group1<-paste(Tol_ScoreTP_M8_lm.geno$Site, Tol_ScoreTP_M8_lm.geno$group1, sep="_")
Tol_ScoreTP_M8_lm.geno$group2<-paste(Tol_ScoreTP_M8_lm.geno$Site, Tol_ScoreTP_M8_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreTP_M8_lm.site<-data.frame(emmeans(Tol_ScoreTP_M8_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreTP_M8_lm.site<-Tol_ScoreTP_M8_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M8_lm.site$group1<-paste(Tol_ScoreTP_M8_lm.site$group1, Tol_ScoreTP_M8_lm.site$Genotype, sep="_")
Tol_ScoreTP_M8_lm.site$group2<-paste(Tol_ScoreTP_M8_lm.site$group2, Tol_ScoreTP_M8_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreTP_M8_lm.p<-rbind(Tol_ScoreTP_M8_lm.geno[,c(1:2,4:8)], Tol_ScoreTP_M8_lm.site[,c(1:2,4:8)])
Tol_ScoreTP_M8_lm.p<-Tol_ScoreTP_M8_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreTP_M8_lm.p$Sig<-ifelse(Tol_ScoreTP_M8_lm.p$p<0.001, "***", ifelse(Tol_ScoreTP_M8_lm.p$p<0.01, "**", ifelse(Tol_ScoreTP_M8_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreTP_M8_lm.p$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M8_lm.p))
Tol_ScoreTP_M8_lm.p$TimeP<-rep("M8", nrow(Tol_ScoreTP_M8_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreTP_M8_SG<-summarySE(TolData_M8, measurevar="Score_TP.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreTP_M8_SG.plot<-ggplot(Tol_ScoreTP_M8_SG, aes(x=Site.Geno, y=Score_TP.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_TP.prop-se, ymax=Score_TP.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention by Timepoint")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o); Tol_ScoreTP_M8_SG.plot
#+ stat_pvalue_manual(data=Tol_ScoreTP_M8_lm.p, y.position=0.65, step.increase=0.25, label="Sig", hide.ns=TRUE) #No significant differences
##Check normality
hist(TolData_M12$Score_TP.prop)
shapiro.test(TolData_M12$Score_TP.prop)
Shapiro-Wilk normality test
data: TolData_M12$Score_TP.prop
W = 0.96756, p-value = 0.6074
#Normal
##Model as a function of Site and Genotype
Tol_ScoreTP_M12_lm<-lm(Score_TP.prop~Site+Genotype+Site:Genotype, data=TolData_M12)
##Check Normality of Residuals
#Distribution
plot(density(resid(Tol_ScoreTP_M12_lm)))
#Q-Q plot
qqnorm(resid(Tol_ScoreTP_M12_lm)); qqline(resid(Tol_ScoreTP_M12_lm))
##Check Variance of Residuals across Fitted Values
plot(fitted(Tol_ScoreTP_M12_lm), resid(Tol_ScoreTP_M12_lm))
#Model Results
summary(Tol_ScoreTP_M12_lm)
Call:
lm(formula = Score_TP.prop ~ Site + Genotype + Site:Genotype,
data = TolData_M12)
Residuals:
Min 1Q Median 3Q Max
-0.117625 -0.052444 -0.007313 0.045694 0.180200
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 0.796079 0.017504 45.479 <2e-16 ***
Site.L -0.006170 0.024755 -0.249 0.806
Genotype.L -0.002961 0.030319 -0.098 0.923
Genotype.Q 0.006986 0.030319 0.230 0.820
Site.L:Genotype.L 0.014288 0.042877 0.333 0.743
Site.L:Genotype.Q -0.034966 0.042877 -0.815 0.425
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.08575 on 18 degrees of freedom
Multiple R-squared: 0.04766, Adjusted R-squared: -0.2169
F-statistic: 0.1802 on 5 and 18 DF, p-value: 0.9665
anova(Tol_ScoreTP_M12_lm)
Analysis of Variance Table
Response: Score_TP.prop
Df Sum Sq Mean Sq F value Pr(>F)
Site 1 0.000457 0.0004568 0.0621 0.8060
Genotype 2 0.000461 0.0002303 0.0313 0.9692
Site:Genotype 2 0.005707 0.0028535 0.3880 0.6839
Residuals 18 0.132367 0.0073537
#Effect Size of Predictors
eta_squared(Tol_ScoreTP_M12_lm, partial=FALSE)
# Effect Size for ANOVA (Type I)
Parameter | Eta2 | 95% CI
---------------------------------------
Site | 3.29e-03 | [0.00, 1.00]
Genotype | 3.31e-03 | [0.00, 1.00]
Site:Genotype | 0.04 | [0.00, 1.00]
- One-sided CIs: upper bound fixed at [1.00].
##Save model results
Tol_ScoreTP_M12_lm.res<-data.frame(anova(Tol_ScoreTP_M12_lm))
Tol_ScoreTP_M12_lm.res$Predictor<-rownames(Tol_ScoreTP_M12_lm.res)
Tol_ScoreTP_M12_lm.res$EtaSq<-c(eta_squared(Tol_ScoreTP_M12_lm, partial=FALSE)$Eta2, NA)
Tol_ScoreTP_M12_lm.res$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M12_lm.res))
Tol_ScoreTP_M12_lm.res$TimeP<-rep("M12", nrow(Tol_ScoreTP_M12_lm.res))
Tol_ScoreTP_M12_lm.res<-Tol_ScoreTP_M12_lm.res %>% dplyr::rename( p.value = "Pr..F.", DF= "Df")
No significant effects of Site or Genotype. Still checking Site*Genotype for comparability across Timepoints.
#Pairwise comparisons across:
#Genotypes within Sites
emmeans(Tol_ScoreTP_M12_lm, pairwise~Genotype | Site)
$emmeans
Site = KL:
Genotype emmean SE df lower.CL upper.CL
AC10 0.823 0.0429 18 0.733 0.913
AC12 0.775 0.0429 18 0.684 0.865
AC8 0.804 0.0429 18 0.714 0.894
Site = SS:
Genotype emmean SE df lower.CL upper.CL
AC10 0.779 0.0429 18 0.689 0.870
AC12 0.806 0.0429 18 0.716 0.896
AC8 0.790 0.0429 18 0.699 0.880
Confidence level used: 0.95
$contrasts
Site = KL:
contrast estimate SE df t.ratio p.value
AC10 - AC12 0.0481 0.0606 18 0.793 0.7121
AC10 - AC8 0.0185 0.0606 18 0.305 0.9503
AC12 - AC8 -0.0296 0.0606 18 -0.488 0.8778
Site = SS:
contrast estimate SE df t.ratio p.value
AC10 - AC12 -0.0268 0.0606 18 -0.442 0.8987
AC10 - AC8 -0.0101 0.0606 18 -0.167 0.9848
AC12 - AC8 0.0167 0.0606 18 0.275 0.9593
P value adjustment: tukey method for comparing a family of 3 estimates
#Sites within Genotypes
emmeans(Tol_ScoreTP_M12_lm, pairwise~Site | Genotype)
$emmeans
Genotype = AC10:
Site emmean SE df lower.CL upper.CL
KL 0.823 0.0429 18 0.733 0.913
SS 0.779 0.0429 18 0.689 0.870
Genotype = AC12:
Site emmean SE df lower.CL upper.CL
KL 0.775 0.0429 18 0.684 0.865
SS 0.806 0.0429 18 0.716 0.896
Genotype = AC8:
Site emmean SE df lower.CL upper.CL
KL 0.804 0.0429 18 0.714 0.894
SS 0.790 0.0429 18 0.699 0.880
Confidence level used: 0.95
$contrasts
Genotype = AC10:
contrast estimate SE df t.ratio p.value
KL - SS 0.0432 0.0606 18 0.712 0.4853
Genotype = AC12:
contrast estimate SE df t.ratio p.value
KL - SS -0.0316 0.0606 18 -0.522 0.6081
Genotype = AC8:
contrast estimate SE df t.ratio p.value
KL - SS 0.0146 0.0606 18 0.241 0.8121
##Save p-values
#Genotypes within Sites
Tol_ScoreTP_M12_lm.geno<-data.frame(emmeans(Tol_ScoreTP_M12_lm, pairwise~Genotype | Site)$contrasts)
Tol_ScoreTP_M12_lm.geno<-Tol_ScoreTP_M12_lm.geno %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M12_lm.geno$group1<-paste(Tol_ScoreTP_M12_lm.geno$Site, Tol_ScoreTP_M12_lm.geno$group1, sep="_")
Tol_ScoreTP_M12_lm.geno$group2<-paste(Tol_ScoreTP_M12_lm.geno$Site, Tol_ScoreTP_M12_lm.geno$group2, sep="_")
#Sites within Genotypes
Tol_ScoreTP_M12_lm.site<-data.frame(emmeans(Tol_ScoreTP_M12_lm, pairwise~Site | Genotype)$contrasts)
Tol_ScoreTP_M12_lm.site<-Tol_ScoreTP_M12_lm.site %>% separate(col=contrast, into=c("group1", "group2"), sep=" - ", remove=TRUE)
Tol_ScoreTP_M12_lm.site$group1<-paste(Tol_ScoreTP_M12_lm.site$group1, Tol_ScoreTP_M12_lm.site$Genotype, sep="_")
Tol_ScoreTP_M12_lm.site$group2<-paste(Tol_ScoreTP_M12_lm.site$group2, Tol_ScoreTP_M12_lm.site$Genotype, sep="_")
#Full list of p-values
Tol_ScoreTP_M12_lm.p<-rbind(Tol_ScoreTP_M12_lm.geno[,c(1:2,4:8)], Tol_ScoreTP_M12_lm.site[,c(1:2,4:8)])
Tol_ScoreTP_M12_lm.p<-Tol_ScoreTP_M12_lm.p %>% dplyr::rename( p = p.value)
#Add Significance Levels
Tol_ScoreTP_M12_lm.p$Sig<-ifelse(Tol_ScoreTP_M12_lm.p$p<0.001, "***", ifelse(Tol_ScoreTP_M12_lm.p$p<0.01, "**", ifelse(Tol_ScoreTP_M12_lm.p$p<0.05, "*", NA)))
#Specify Response and Timepoint
Tol_ScoreTP_M12_lm.p$Response<-rep("Color_TP", nrow(Tol_ScoreTP_M12_lm.p))
Tol_ScoreTP_M12_lm.p$TimeP<-rep("M12", nrow(Tol_ScoreTP_M12_lm.p))
##Summary statistics by Site and Genotype
Tol_ScoreTP_M12_SG<-summarySE(TolData_M12, measurevar="Score_TP.prop", groupvars=c("Site.Geno", "Site", "Genotype"), na.rm=TRUE)
##Plot Average Retention across Treatments
Tol_ScoreTP_M12_SG.plot<-ggplot(Tol_ScoreTP_M12_SG, aes(x=Site.Geno, y=Score_TP.prop, colour=Genotype)) +
geom_errorbar(aes(ymin=Score_TP.prop-se, ymax=Score_TP.prop+se), width=cap.sz, linewidth=bar.sz)+
geom_point(size=point.sz)+
ggtitle("Color Retention by Timepoint")+
theme_classic()+
theme( axis.title.x = element_text(size = axis.title.sz),
axis.title.y = element_text(size = axis.title.sz),
axis.text.x=element_text(size=axis.txt.sz, colour="black"),
axis.text.y=element_text(size=axis.txt.sz, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
legend.box.background = element_rect(color = "black"),
legend.position="bottom",
legend.direction="horizontal",
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="Proportion Retained")+
ylim(0, 1.5)+
scale_x_discrete(labels=c("","Klein","","","Something Special",""))+
scale_color_manual(values = Geno.colors.o); Tol_ScoreTP_M12_SG.plot
#+ stat_pvalue_manual(data=Tol_ScoreTP_M12_lm.p, y.position=0.8, step.increase=0.15, label="Sig", hide.ns=TRUE) #No significant differences
Creating a heatmap to compare the direction and significance of pairwise comparisons across Tolerance metrics. Positive estimates indicate that Group 1 > Group 2. P values of less than 0.05 are considered significant.
##Combine Results
Tol_contrasts<-rbind(Tol_Chl_W1_lm.p, Tol_Chl_W2_lm.p, Tol_Chl_M1_lm.p,
Tol_Chl_M4_lm.p, Tol_Chl_M8_lm.p, Tol_Chl_M12_lm.p,
Tol_Sym_W2_lm.p, Tol_Sym_M1_lm.p,
Tol_Sym_M4_lm.p, Tol_Sym_M8_lm.p, Tol_Sym_M12_lm.p,
Tol_ScoreF_W1_lm.p, Tol_ScoreF_W2_lm.p,
Tol_ScoreF_M1_lm.p, Tol_ScoreF_M4_lm.p,
Tol_ScoreF_M8_lm.p, Tol_ScoreF_M12_lm.p,
Tol_ScoreTP_W1_lm.p, Tol_ScoreTP_W2_lm.p,
Tol_ScoreTP_M1_lm.p, Tol_ScoreTP_M4_lm.p,
Tol_ScoreTP_M8_lm.p, Tol_ScoreTP_M12_lm.p)
##Create Contrast Column
Tol_contrasts$Contrast<-paste(Tol_contrasts$group1, Tol_contrasts$group2, sep=" v. ")
Convert Estimate to the Response scale (instead of log +1 scale) for models where the response was log transformed
Tol_contrasts$Estimate<-Tol_contrasts$estimate
#Chl W1
Tol_contrasts$Estimate[which(Tol_contrasts$Response=="Chlorophyll" & Tol_contrasts$TimeP=="W1")]<-c(exp(Tol_contrasts$estimate[which(Tol_contrasts$Response=="Chlorophyll" & Tol_contrasts$TimeP=="W1")])-1)
#Chl M4
Tol_contrasts$Estimate[which(Tol_contrasts$Response=="Chlorophyll" & Tol_contrasts$TimeP=="M4")]<-c(exp(Tol_contrasts$estimate[which(Tol_contrasts$Response=="Chlorophyll" & Tol_contrasts$TimeP=="M4")])-1)
#Chl M12
Tol_contrasts$Estimate[which(Tol_contrasts$Response=="Chlorophyll" & Tol_contrasts$TimeP=="M12")]<-c(exp(Tol_contrasts$estimate[which(Tol_contrasts$Response=="Chlorophyll" & Tol_contrasts$TimeP=="M12")])-1)
#Sym M1
Tol_contrasts$Estimate[which(Tol_contrasts$Response=="Symbionts" & Tol_contrasts$TimeP=="M1")]<-c(exp(Tol_contrasts$estimate[which(Tol_contrasts$Response=="Symbionts" & Tol_contrasts$TimeP=="M1")])-1)
Tol_Pairs_W1.plot<-ggplot(data=Tol_contrasts[which(Tol_contrasts$TimeP=="W1"),], aes(x=Response, y=Contrast, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Pairwise Contrasts Week 1")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_W1.plot
Tol_Pairs_W2.plot<-ggplot(data=Tol_contrasts[which(Tol_contrasts$TimeP=="W2"),], aes(x=Response, y=Contrast, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Pairwise Contrasts Week 2")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_W2.plot
Tol_Pairs_M1.plot<-ggplot(data=Tol_contrasts[which(Tol_contrasts$TimeP=="M1"),], aes(x=Response, y=Contrast, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Pairwise Contrasts Month 1")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_M1.plot
Tol_Pairs_M4.plot<-ggplot(data=Tol_contrasts[which(Tol_contrasts$TimeP=="M4"),], aes(x=Response, y=Contrast, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Pairwise Contrasts Month 4")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_M4.plot
Tol_Pairs_M8.plot<-ggplot(data=Tol_contrasts[which(Tol_contrasts$TimeP=="M8"),], aes(x=Response, y=Contrast, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Pairwise Contrasts Month 8")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_M8.plot
Tol_Pairs_M12.plot<-ggplot(data=Tol_contrasts[which(Tol_contrasts$TimeP=="M12"),], aes(x=Response, y=Contrast, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Pairwise Contrasts Month 12")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_M12.plot
Subsetting Contrasts to only include contrasts with significant differences in at least one of the thermal tolerance metrics (Chlorophyll or Symbiont or Color retention)
##Add Set column with Contrast and Timepoint
Tol_contrasts$Set<-paste(Tol_contrasts$TimeP, Tol_contrasts$Contrast, sep=" ")
##Remove rows with non-significant p-values
Tol_contrasts_sig<-subset(Tol_contrasts, p < 0.05)
##Keep Sets where at least one metric shows a significant difference
Tol_Sets_sig<-data.frame(Set=c(unique(Tol_contrasts_sig$Set)))
Tol_contrasts_sig_Set<-merge(Tol_Sets_sig, Tol_contrasts, all.x=TRUE, all.y=FALSE)
##Re-order by Timepoint
Tol_contrasts_sig_Set$TimeP<-factor(Tol_contrasts_sig_Set$TimeP, levels=c("W1", "W2", "M1", "M4", "M8", "M12"), ordered=TRUE)
Tol_contrasts_sig_Set<- Tol_contrasts_sig_Set %>% arrange(desc(as.numeric(TimeP)))
Tol_contrasts_sig_Set$Set<-factor(Tol_contrasts_sig_Set$Set, levels=c(unique(Tol_contrasts_sig_Set$Set)), ordered=TRUE)
Tol_Pairs_sig.plot<-ggplot(data=Tol_contrasts_sig_Set, aes(x=Response, y=Set, fill=Estimate))+
geom_tile()+
geom_text(aes(label=Sig), size=sig.sz)+
scale_fill_gradient2(low="#BA1E02FF", mid="white", high="#3BA0FDFF")+
theme_bw()+
ggtitle("Significant Pairwise Contrasts")+
theme(axis.text.x=element_text(size=axis.title.sz, colour="black", angle=45, hjust=1),
axis.text.y=element_text(size=axis.txt.sz-1, colour="black"),
legend.text=element_text(size=leg.txt.sz),
legend.title=element_text(size=leg.title.sz),
plot.title = element_text(size = plot.title.sz, colour="black", hjust = 0.5))+
labs(x="", y="", fill="Estimate");Tol_Pairs_sig.plot
##Create Panel
Tolerance_W1_fig<-plot_grid(Tol_Pairs_W1.plot, Tol_Chl_W1_SG.plot,
Tol_ScoreF_W1_SG.plot, Tol_ScoreTP_W1_SG.plot,
nrow=1, ncol=4,
rel_widths=c(1, 0.75, 0.75, 0.75), rel_heights=1,
labels=c("A", "B", "C", "D"),
label_size=panel.lab.sz,
label_fontface = "bold")
Warning: Removed 17 rows containing missing values (`geom_text()`).
##Save Figure
ggsave(filename="Figures/Tolerance_W1.png", plot=Tolerance_W1_fig, dpi=300, width=20, height=6, units="in")
##Create Panel
Tolerance_W2_fig<-plot_grid(Tol_Pairs_W2.plot,
Tol_Chl_W2_SG.plot, Tol_ScoreF_W2_SG.plot,
Tol_ScoreTP_W2_SG.plot, Tol_Sym_W2_SG.plot,
nrow=1, ncol=5,
rel_widths=c(1, 0.75, 0.75, 0.75, 0.75),
rel_heights=1,
labels=c("A", "B", "C", "D", "E"),
label_size=panel.lab.sz,
label_fontface = "bold")
Warning: Removed 21 rows containing missing values (`geom_text()`).
##Save Figure
ggsave(filename="Figures/Tolerance_W2.png", plot=Tolerance_W2_fig, dpi=300, width=25, height=6, units="in")
##Create Panel
Tolerance_M1_fig<-plot_grid(Tol_Pairs_M1.plot,
Tol_Chl_M1_SG.plot, Tol_ScoreF_M1_SG.plot,
Tol_ScoreTP_M1_SG.plot, Tol_Sym_M1_SG.plot,
nrow=1, ncol=5,
rel_widths=c(1, 0.75, 0.75, 0.75, 0.75),
rel_heights=1,
labels=c("A", "B", "C", "D", "E"),
label_size=panel.lab.sz,
label_fontface = "bold")
Warning: Removed 17 rows containing missing values (`geom_text()`).
##Save Figure
ggsave(filename="Figures/Tolerance_M1.png", plot=Tolerance_M1_fig, dpi=300, width=25, height=6, units="in")
##Create Panel
Tolerance_M4_fig<-plot_grid(Tol_Pairs_M4.plot,
Tol_Chl_M4_SG.plot, Tol_ScoreF_M4_SG.plot,
Tol_ScoreTP_M4_SG.plot, Tol_Sym_M4_SG.plot,
nrow=1, ncol=5,
rel_widths=c(1, 0.75, 0.75, 0.75, 0.75),
rel_heights=1,
labels=c("A", "B", "C", "D", "E"),
label_size=panel.lab.sz,
label_fontface = "bold")
Warning: Removed 16 rows containing missing values (`geom_text()`).
##Save Figure
ggsave(filename="Figures/Tolerance_M4.png", plot=Tolerance_M4_fig, dpi=300, width=25, height=6, units="in")
##Create Panel
Tolerance_M8_fig<-plot_grid(Tol_Pairs_M8.plot,
Tol_Chl_M8_SG.plot, Tol_ScoreF_M8_SG.plot,
Tol_ScoreTP_M8_SG.plot, Tol_Sym_M8_SG.plot,
nrow=1, ncol=5,
rel_widths=c(1, 0.75, 0.75, 0.75, 0.75),
rel_heights=1,
labels=c("A", "B", "C", "D", "E"),
label_size=panel.lab.sz,
label_fontface = "bold")
Warning: Removed 29 rows containing missing values (`geom_text()`).
##Save Figure
ggsave(filename="Figures/Tolerance_M8.png", plot=Tolerance_M8_fig, dpi=300, width=25, height=6, units="in")
##Create Panel
Tolerance_M12_fig<-plot_grid(Tol_Pairs_M12.plot,
Tol_Chl_M12_SG.plot, Tol_ScoreF_M12_SG.plot,
Tol_ScoreTP_M12_SG.plot, Tol_Sym_M12_SG.plot,
nrow=1, ncol=5,
rel_widths=c(1, 0.75, 0.75, 0.75, 0.75),
rel_heights=1,
labels=c("A", "B", "C", "D", "E"),
label_size=panel.lab.sz,
label_fontface = "bold")
Warning: Removed 36 rows containing missing values (`geom_text()`).
##Save Figure
ggsave(filename="Figures/Tolerance_M12.png", plot=Tolerance_M12_fig, dpi=300, width=25, height=6, units="in")
##Save Figure
ggsave(filename="Figures/Tolerance_Heatmap.png", plot=Tol_Pairs_sig.plot, dpi=300, width=8, height=12, units="in")
##Combine Results Tables
TableS2_Tol.lm.res<-rbind(Tol_Chl_W1_lm.res, Tol_Chl_W2_lm.res,
Tol_Chl_M1_lm.res, Tol_Chl_M4_lm.res,
Tol_Chl_M8_lm.res, Tol_Chl_M12_lm.res,
Tol_Sym_W2_lm.res,
Tol_Sym_M1_lm.res, Tol_Sym_M4_lm.res,
Tol_Sym_M8_lm.res, Tol_Sym_M12_lm.res,
Tol_ScoreF_W1_lm.res, Tol_ScoreF_W2_lm.res,
Tol_ScoreF_M1_lm.res, Tol_ScoreF_M4_lm.res,
Tol_ScoreF_M8_lm.res, Tol_ScoreF_M12_lm.res,
Tol_ScoreTP_W1_lm.res, Tol_ScoreTP_W2_lm.res,
Tol_ScoreTP_M1_lm.res, Tol_ScoreTP_M4_lm.res,
Tol_ScoreTP_M8_lm.res, Tol_ScoreTP_M12_lm.res)
##Organize
names(TableS2_Tol.lm.res)
[1] "DF" "Sum.Sq" "Mean.Sq" "F.value" "p.value" "Predictor"
[7] "EtaSq" "Response" "TimeP"
TableS2_Tol.lm.res<-TableS2_Tol.lm.res[,c("TimeP", "Response", "Predictor", "DF", "Sum.Sq", "Mean.Sq", "F.value", "p.value", "EtaSq")]
#Round to 4 digits
TableS2_Tol.lm.res$Sum.Sq<-round(TableS2_Tol.lm.res$Sum.Sq, 4)
TableS2_Tol.lm.res$Mean.Sq<-round(TableS2_Tol.lm.res$Mean.Sq, 4)
TableS2_Tol.lm.res$F.value<-round(TableS2_Tol.lm.res$F.value, 4)
TableS2_Tol.lm.res$p.value<-round(TableS2_Tol.lm.res$p.value, 4)
TableS2_Tol.lm.res$EtaSq<-round(TableS2_Tol.lm.res$EtaSq, 4)
##Write Out Table
write.csv(TableS2_Tol.lm.res, "Tables/TableS2_Tolerance_LM_Results.csv", row.names=FALSE)
##Pairwise Results Table
TableS3_Tol.pairwise<-Tol_contrasts
##Organize
names(TableS3_Tol.pairwise)
[1] "group1" "group2" "estimate" "SE" "df" "t.ratio" "p"
[8] "Sig" "Response" "TimeP" "Contrast" "Estimate" "Set"
TableS3_Tol.pairwise<-TableS3_Tol.pairwise[,c("TimeP", "Response", "Contrast", "Estimate", "SE", "df", "t.ratio", "p")]
TableS3_Tol.pairwise<-TableS3_Tol.pairwise %>% dplyr::rename( DF = df) %>% dplyr::rename( p.value = p)
#Round to 4 digits
TableS3_Tol.pairwise$Estimate<-round(TableS3_Tol.pairwise$Estimate, 4)
TableS3_Tol.pairwise$SE<-round(TableS3_Tol.pairwise$SE, 4)
TableS3_Tol.pairwise$t.ratio<-round(TableS3_Tol.pairwise$t.ratio, 4)
TableS3_Tol.pairwise$p.value<-round(TableS3_Tol.pairwise$p.value, 4)
##Write Out Table
write.csv(TableS3_Tol.pairwise, "Tables/TableS3_Tolerance_Pairwise_Results.csv", row.names=FALSE)